From: Patrick Steinhardt <ps@pks.im>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] revert: initialize const value
Date: Mon, 4 Aug 2025 15:35:54 +0200 [thread overview]
Message-ID: <aJC3OiJoqJRnR_My@pks.im> (raw)
In-Reply-To: <20250804130141.GA95101@coredump.intra.peff.net>
On Mon, Aug 04, 2025 at 09:01:41AM -0400, Jeff King wrote:
> On Mon, Aug 04, 2025 at 09:00:12AM -0400, Jeff King wrote:
>
> > 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.
Initializing the value feels like a pragmatic choice to me. There is no
downside, and anyone who might be puzzled by the comment is likely to
git-blame(1) to your commit anyway. So I think the current version is
good enough.
Thanks!
Patrick
next prev parent reply other threads:[~2025-08-04 13:36 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 13:00 [PATCH] revert: initialize const value Jeff King
2025-08-04 13:01 ` Jeff King
2025-08-04 13:35 ` Patrick Steinhardt [this message]
2025-08-04 13:51 ` Phillip Wood
2025-08-04 14:26 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aJC3OiJoqJRnR_My@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.