[BusyBox] uname patch and questions

Manuel Novoa III mjn3 at busybox.net
Wed Nov 28 08:38:53 UTC 2001


David,

On Mon, Nov 26, 2001 at 10:02:54PM -0800, David Schleef wrote:
> On Mon, Nov 26, 2001 at 09:51:02PM -0700, Manuel Novoa III wrote:
> > 
> > > The only thing i would change would be to declare utsname_offset[],
> > > options[] and flags[] inside uname_main() as that the only place they
> > > are used. Is there a reason not to, or is it just aesthetics ?
> > 
> > Just my style really.  I tend to put static const tables outside of
> > function definitions.
> 
> Here's some justification for your style:
>
> int ack1(int x)
> {
> 	const int array[10] = {1,2,3,4 };
> 	return array[x];
> }
> 
> const int array[10] = {1,2,3,4 };
> int ack2(int x)
> {
> 	return array[x];
> }
> 
> ack1 compiles to 100 bytes, not including the call to memcpy, vs.
> ack2's 20 bytes.  (Compiled on PowerPC.)

Well... even though ack1 qualifies array as const, it is declared
with dynamic duration.  I don't know what the fine print in the
standard would say, but it doesn't surprise me that some compilers
would blindly allocate and initialize (via a hidden memcpy in your
case) array on each function call in spite of array's const nature
and the apparent oportunity for optimization.

>                                           If you make the first
> one 'static const', they are the same -- although I don't trust
> the compiler to get it right 100% of the time.

I'm curious about your distrust of the compiler here.  Are you aware
of any problems regarding static declarations at block vs. file scope?

Manuel






More information about the busybox mailing list