Subject: Re: [PATCH 08/12] skip_prefix(): check const match between in and out params

From: Junio C Hamano <[email-masked]>
Date: Wed, 01 Apr 2026 15:13:11 -0700

Jeff King <[email-masked]> writes:

>> > > +#define CONST_OUTPARAM(in, out) \
>> > > +    ((const char **)(0 ? ((*(out) = (in)),(out)) : (out)))
>> > > +#define skip_prefix(str, prefix, out) \
>> > > +    skip_prefix((str), (prefix), CONST_OUTPARAM((str), (out)))
>> > 
>> > This is clever but it changes the behavior of skip_prefix() which is
>> > documented as not touching out if it returns false.
>> 
>> Sorry, I've just realized we always take the other branch so this does not
>> change the behavior and is in fact a nice solution to the problem.
>
> Yeah, exactly. I was curious if the dead branch would be left in place,
> but gcc seems to prune it even at -O0.
>
> I also pondered whether:
>
>   (*out = in,out)
>
> might be a problem, but I think it is OK. The "," is a sequence point,
> so it is well defined (of course we would never run this code anyway,
> but if we have undefined behavior in the code at all, it may cause
> confusing effects).

Yup, the part I like this the most is that this is still well
defined, and the never-taken side of the ternary will not cause us
trouble.

Very nicely done.