git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressions

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 29, 2007, 16:58 UTC
Message-ID
<7vd4w1l872.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<200709291400.13880.andyparkins@gmail.com>
Andy Parkins <andyparkins@gmail.com> writes:
Show 12 quoted lines
> 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 <string.h>
        foo = strlen(PATH_REMOTES)
anyway?
Previous: Andy ParkinsNext: Linus Torvalds
Message 2 of 3 in “Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressions”
  1. 2/2 Replace literal STRLEN_ #defines in refs.h with compiler evaluated expressionsAndy Parkins, Sep 29, 2007
  2. Junio C HamanoSep 29, 2007
  3. Linus TorvaldsSep 29, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.