Re: [PATCH] fs: Cleanup string initializations (char[] instead of char *)

Manuel Schoelling
2014-05-18T10:01:53Z

Thanks for the detailed review of my patches, guys!

I had a look at the assembler code now, too and you are right about
this.
I was misguided by the KernelJanitor's TODO list [1]. If there is
consensus the corresponding paragraph from that list should be removed.

[1] http://kernelnewbies.org/KernelJanitors/Todo

On Sa, 2014-05-17 at 17:53 +0100, Al Viro wrote:
> On Sat, May 17, 2014 at 05:00:18PM +0200, Manuel Schölling wrote:
> > Initializations like 'char *foo = "bar"' will create two variables: a static
> > string and a pointer (foo) to that static string. Instead 'char foo[] = "bar"'
> > will declare a single variable and will end up in shorter
> > assembly (according to Jeff Garzik on the KernelJanitor's TODO list).
>
> The hell it will. Compare assembler generated e.g. for 32bit x86 before
> and after.
>
> > {
> > char *dp;
> > char *status = "disabled";
> > - const char * flags = "flags: ";
> > + const char flags[] = "flags: ";
>
> The first variant puts address of constant array into local variable
> (on stack or in a register). The second one fills local _array_ - the
> string itself goes on stack.