[tz] gcc 8 demanded patch (from NetBSD)

Guy Harris guy at alum.mit.edu
Thu May 11 08:50:14 UTC 2017


On May 10, 2017, at 6:33 AM, Clive D.W. Feather <clive at davros.org> wrote:

> Robert Elz said:
>> The following patch was recently added to NetBSD, to appease
>> GCC 8 (apparently) ... "hit" is a bool, and it seems gcc 8 does
>> not like ++ operators applied to one of those.
> 
> Hmm. It's legal, but it suggests dubious thinking on the part of whoever
> wrote it. It's exactly equivalent to "q = true".

As long as you do it fewer than 2^{number of bits in q} times.  If q is a 32-bit variable, it's probably safe, but I still prefer "q = true", both for readability reasons and "there is no corner case where it doesn't do what you want" reasons - even if it's known that you'll increment it only once, as the "readability reasons" still apply.

> ("q--" is equivalent to "q = !q".)

As long as q is 0 or 1, if it's being treated as a traditional C "Boolean".  But, again, for both readability and corner-case reasons, I'd avoid it.

And "legal but suggests dubious thinking" is a lot of what GCC/clang/etc. warnings are all about - they're not illegal, so they're not errors by default, although GCC, clang, and probably other compilers can be told to treat them as errors.


More information about the tz mailing list