Re: [PATCH] mingw: avoid the comma operator
- From
Jeff King <peff@peff.net>
- Date
- Nov 18, 2025, 09:49 UTC
- Message-ID
- <20251118094918.GC530545@coredump.intra.peff.net>
- In-Reply-To
- <xmqqy0o4gv99.fsf@gitster.g>
On Mon, Nov 17, 2025 at 02:16:34PM -0800, Junio C Hamano wrote:
Show 19 quoted lines
> > /* only these flags are supported */
> > - if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
> > - return errno = ENOSYS, -1;
> > + if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
> > + errno = ENOSYS;
> > + return -1;
> > + }
>
> Good riddance. It indeed is somewhat hard to read, especially
> because it may not be apparent to readers how "A = B, C" binds
> (answer: B gets assigned to A and then the whole thing yields C).
>
> I wonder if
>
> return (errno = ENOSYS), -1;
>
> is accepted by the compiler, but in these error handling we do not
> have to be cute, and updated code that is both simple and stupid
> reads very well.Agreed that we are best avoiding comma operators when we can. There is one spot where we use it, though, and I haven't figured out a good way around it: in the error() macro wrapper.
I guess it does not cause the same compiler complaints because there is no assignment in it. So if nobody is complaining, we can just avert our eyes when looking at the macro. :)
-Peff