From: Kim Phillips Date: Sat, 12 Feb 2011 16:04:43 -0600 Subject: [U-Boot] [PATCH v3] mkimage: add "-V" option to print version information In-Reply-To: <4D562D0A.9060800@free.fr> References: <1297414591-12987-1-git-send-email-wd@denx.de> <1297464103-9111-1-git-send-email-wd@denx.de> <20110211171117.b9b05b01.kim.phillips@freescale.com> <4D562D0A.9060800@free.fr> Message-ID: <20110212160443.aadfa098.kim.phillips@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Sat, 12 Feb 2011 07:47:38 +0100 Albert ARIBAUD 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