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

Re: [PATCH] revert: initialize const value

From
Jeff King <peff@peff.net>
Date
Aug 4, 2025, 13:01 UTC
Message-ID
<20250804130141.GA95101@coredump.intra.peff.net>
In-Reply-To
<20250804130011.GA93475@coredump.intra.peff.net>
On Mon, Aug 04, 2025 at 09:00:12AM -0400, Jeff King wrote:
Show 23 quoted lines
> There are a few possible options:
> 
>   1. Instead of a variable, we could just construct an artificial
>      sentinel address like "1", "-1", etc. I think these technically
>      fall afoul of the C standard (even if we do not access them, even
>      constructing invalid pointers is not always allowed). But it's also
>      something we do elsewhere, and even happens in some standard
>      interfaces (e.g., mmap()'s MMAP_FAILED value). It does involve some
>      annoying casts, though.
> 
>   2. We can mark it as static. That gives it a definite value, but
>      perhaps makes people wonder if the static-ness is important, when
>      it's not.
> 
>   3. We can just give it a value to shut the compiler up, even though
>      nobody cares about that value.
> 
> I went with (3) here as the smallest and most obvious change.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> I dunno, maybe the comment just makes things more mysterious and
> doing the casts would make it more clear what is going on.

Hmm, I guess one other option I did not consider: we could just drop the "const". The pointers to it are "const char *", but it is fine for them to point to a non-const variable. Maybe that is less mysterious.

-Peff
Previous: Jeff KingNext: Patrick Steinhardt
Message 2 of 5 in “revert: initialize const value”
  1. revert: initialize const valueJeff King, Aug 4, 2025
  2. Jeff KingAug 4, 2025
  3. Patrick SteinhardtAug 4, 2025
  4. Phillip WoodAug 4, 2025
  5. Junio C HamanoAug 4, 2025

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.