Guy Harris said:
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.
No, q is a bool. When you assign to a bool any non-zero value is converted to 1. So you only need to consider the cases of 0 and 1, both of which will be changed to 1. More precisely, the statement "q++;" is equivalent to: q = (q + 1) != 0 ? 1 : 0; or: q = (q + 1) != 0; Whether q is 0 or 1 (the only two values it can have), this sets q to 1.
("q--" is equivalent to "q = !q".) As long as q is 0 or 1, if it's being treated as a traditional C "Boolean".
No, again I'm talking about the "bool" type in C. (Technically, the type is called "_Bool" and the header <stdbool.h> contains "#define bool _Bool".)
And "legal but suggests dubious thinking" is a lot of what GCC/clang/etc. warnings are all about
Indeed; I'm not objecting to the warning, quite the contrary. -- Clive D.W. Feather | If you lie to the compiler, Email: clive@davros.org | it will get its revenge. Web: http://www.davros.org | - Henry Spencer Mobile: +44 7973 377646