On Sun, Jul 20, 2014 at 11:20:13AM +0300, Timo Teras wrote:
> On Sat, 19 Jul 2014 21:31:33 +0200
> Dan Fandrich <d...@coneharvesters.com> wrote:
> 
> > On Fri, Jul 18, 2014 at 10:07:06PM +0300, Timo Teräs wrote:
> > > and do it in smaller code:
> > > 
> > > diff --git a/procps/top.c b/procps/top.c
> > > index 530f45f..e60dab6 100644
> > > --- a/procps/top.c
> > > +++ b/procps/top.c
> > > @@ -501,10 +501,27 @@ static void display_cpus(int scr_width, char
> > > *scrbuf, int *lines_rem_p) 
> > >  static unsigned long display_header(int scr_width, int
> > > *lines_rem_p) {
> > > + static const char *fields =
> > 
> > Minor suggestion: this should be 
> >     static const char * const fields =
> > 
> > so it can go into .rodata.
> 
> It does go into .rodata already as-is. In fact 'make bloatcheck' says
> there's no difference on sizes depending which form is used. I guess
> this is due to compiler optimization figuring out that it's used only
> locally in the function.

The strings themselves go into .rodata, but the fields pointer itself goes into
.data without the extra const.

> That said, adding the second "const" does make sense. And thinking more,
> "static" should probably be left out.

static needs to be left in in order to avoid a copy of the structure onto the
stack at run-time.

All this may be moot with an optimizing compiler, but not all compilers are
necessarily smart enough to do this on their own. Adding those keywords also
makes it more clear what the intent is of the structure.

>>> Dan
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to