On Sat, 12 Feb 2011 07:47:38 +0100 Albert ARIBAUD <albert.arib...@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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot