From: Junio C Hamano Date: Sat, 29 Sep 2007 16:58:41 GMT Subject: Re: [PATCH 2/2] Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressions Message-ID: <7vd4w1l872.fsf@gitster.siamese.dyndns.org> In-Reply-To: <200709291400.13880.andyparkins@gmail.com> Andy Parkins writes: > Bill Lear pointed out that the following: > > #define PATH_REMOTES "remotes/" > #define STRLEN_PATH_REMOTES 8 > > Could be replaced by the less error-prone > > #define PATH_REMOTES "remotes/" > #define LIT_STRLEN(S) ((sizeof(S) / sizeof(S[0])) -1) > #define STRLEN_PATH_REMOTES LIT_STRLEN(PATH_REMOTES) > > which is what this patch does. I do not think the above is wrong per se, but doesn't a good compiler optimize #define PATH_REMOTES "remotes/" #define STRLEN_PATH_REMOTES strlen(PATH_REMOTES) ... and much later in some *.c file that includes the ... above and foo = strlen(PATH_REMOTES) anyway?