From mboxrd@z Thu Jan 1 00:00:00 1970 From: Albert ARIBAUD Date: Sat, 12 Feb 2011 07:47:38 +0100 Subject: [U-Boot] [PATCH v3] mkimage: add "-V" option to print version information In-Reply-To: <20110211171117.b9b05b01.kim.phillips@freescale.com> 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> Message-ID: <4D562D0A.9060800@free.fr> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Le 12/02/2011 00:11, Kim Phillips a ?crit : > On Fri, 11 Feb 2011 23:41:43 +0100 > Wolfgang Denk wrote: > >> + case 'V': >> + /* >> + * Skip the "U-Boot " part in >> + * U_BOOT_VERSION by adding 7 >> + */ >> + printf("mkimage version %s\n", >> + U_BOOT_VERSION + 7); Now I get it. :) I might argue that this is kind of a hack, and that rather than trying to prune the U_BOOT_VERSION string, one should define two macros, for instance: #define PLAIN_VERSION "whatever" #define U_BOOT_VERSION "U-Boot " PLAIN_VERSION ... which has the advantage of not affecting the existing code, or a cleaner, but more invasive, change... #define U_BOOT_VERSION "whatever" /* without "U-Boot " */ #define U_BOOT_VERSION_BANNER "U-Boot " U_BOOT_VERSION ... and use the right macro for the right need. > 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. > Kim Amicalement, -- Albert.