[PATCH 2/3] flash_eraseall: move constants out of for loop

Jamie Lokier jamie at shareable.org
Wed Jun 23 20:39:54 EDT 2010


Mike Frysinger wrote:
> On Tue, Jun 22, 2010 at 20:23, Jamie Lokier wrote:
> > Mike Frysinger wrote:
> >> i wonder though why this code even bothers with "static".
> >
> > The array is static to avoid compiling to code which fills in the
> > array at runtime.  I.e. it makes the code smaller, to the same size as
> > if they were globals.  And then, only because its static, the const
> > can put them in the .rodata section, reducing unshared data size.
> 
> if it were generated on the stack at runtime, the .text is shared too

Shared, but larger than the static-const data it replaces.

> > Because they're static there's no benefit to moving them to another
> > scope.
> 
> that's sort of what i expected, but i found it odd that it isnt:
>     static const char * const short_options = "jq";

You're right, I missed that.
I'd have used this myself:

static const char short_options[] = "jq";

-- Jamie




More information about the linux-mtd mailing list