Re: [PATCH] vsprintf: reduce code size, clean up

From: Frederic Weisbecker
Date: Sun Nov 01 2009 - 18:19:03 EST


On Sun, Nov 01, 2009 at 09:00:48PM -0200, Andrà Goddard Rosa wrote:
> Hi, Frederic!
>
> On Sun, Nov 1, 2009 at 8:45 PM, Frederic Weisbecker <fweisbec@xxxxxxxxx> wrote:
> > On Sun, Nov 01, 2009 at 03:01:40PM -0200, Andrà Goddard Rosa wrote:
> >> +static char null[] = "(null)";
> >> +
> >
> >
> > This should be static const.
> > Also, may be chose a better name, as "null" is too much
> > generic and somehow collide with NULL.
> >
> > null_str ?
> >
>
> If I make it a "static const" it's necessary to cast it in two places
> to "char *" and code size goes up
>
> lib/vsprintf.c: In function âstringâ:
> lib/vsprintf.c:556: warning: assignment discards qualifiers from
> pointer target type
> lib/vsprintf.c: In function âpointerâ:
> lib/vsprintf.c:828: warning: passing argument 3 of âstringâ discards
> qualifiers from pointer target type
> lib/vsprintf.c:551: note: expected âchar *â but argument is of type
> âconst char *â
>
> text data bss dec hex filename
> 15383 7 8 15398 3c26 lib/vsprintf.o-static-before
> 15431 0 8 15439 3c4f lib/vsprintf.o-static-const-after
>
> as it moves the variable from data section to code section. Is this
> the preferred method?
>


Hm, that:

static const char *null = "(null)";

is supposed to go to .rodata

Anyway, yeah better make it a const. When it's used, the variable
is not changed.

save_str in vbin_printf() is already a const char.
The "s" parameter in string() can be safely turned into const.


> Thanks for reviewing! I'll fix the other points per your suggestions
> and post back.
>
> With regards,
> AndrÃ


Thanks.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/