[U-Boot] [PATCH v3] mkimage: add "-V" option to print version information

Kim Phillips kim.phillips at freescale.com
Sat Feb 12 23:04:43 CET 2011


On Sat, 12 Feb 2011 07:47:38 +0100
Albert ARIBAUD <albert.aribaud at free.fr> wrote:

> Le 12/02/2011 00:11, Kim Phillips a écrit :
> > I'd have done it without magic nor comments as
> >
> > U_BOOT_VERSION[sizeof("U-Boot ") + 1]
> >
> > or even
> >
> > U_BOOT_VERSION[strlen("U-Boot ")]
> 
> The second one calls strlen() at run-time, plus it allocates the "U-Boot 
> " string for no justifiable reason -- assuming the first one can be 
> compile-time evaluated by the compiler, of course.

no, the compiler evaluates the strlen at compile time and eliminates
the need to allocate the "U-Boot " string in both cases.

that's not to say that there aren't a couple of gaffes above: the
sizeof needs a - 1 instead of a + 1 (because it includes the trailing
'\0'), and both expressions need to be prepended with an '&'.  So, we
have something like:

&U_BOOT_VERSION[sizeof("U-Boot ") - 1]

or

&U_BOOT_VERSION[strlen("U-Boot ")]

Kim



More information about the U-Boot mailing list