Re: [PATCH] revert: initialize const value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
> > ---
> > 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux