On Tue, 22 Jul 2014 13:07:15 -0400
"Cathey, Jim" <[email protected]> wrote:

> >Am I missing something here?  There is no structure, just a
> >character pointer.  If you leave off "static" it will be compiled as
> >an instruction that pushes a constant onto the stack, by any/every
> >compiler.
> 
> Which is probably _larger_ code than just referring to something
> stored in the .text/.data segment.  It's copying something that is
> found in text/data into the stack space, then referring to that
> address thereafter.  The compiler has to do:
> 
>       Copy A->B
>       Then use &B.
> 
> -vs-
> 
>       Use &A.
> 
> You do this when you want the ability to modify B.
> If A is fixed and inviolate, you mark it static const
> and be done with it.  What this turns into, exactly,
> depends upon your compiler, CPU, and ABI, but I can't
> think of any case where the extra copy is going to
> turn out _better_ than the simpler case.

Usage of 'static' depends whether it's "const char *" or "const
char[]". When defining "const char *" static does not make sense, as
in theory it should enforce *also* the pointer value to go to .rodata
(the string literal of course goes there too). So you might end up
wasting one extra pointer in .rodata.

OTOH, with "const char[]" you definitely want the "static" as other
wise you'd end up with the copy described above.

I only suggested removing 'static' since I had it a pointer. The latest
patch has array, and thus is static.

/Timo
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to