News for hackers. Stuff that matters.
Re:Bugs found in GCC with the help of PVS-Studio by mtkd on Saturday September 03, 2016 @05:53AM (#12418551)
a == 1 || a != 2 needs a warning but it's not necessarily a bug

sometimes I may keep overlapping expressions in a statement to remind me of the triggers I'm looking for at this point - and would likely use some meaningful constant names for the 1 and 2

statements aren't just logic - they're often documentation too - especially on code you might not look at again for months

I used to have many arguments with a professor whose code I was working on - he would factor out everything in an expression - removing all the parentheses and rely on operator precedence - it was often impenetrable (for me) - so I'd unpack it, wrap parentheses everywhere, change single letter vars to meaningful ones etc. - he'd be in my office an hour later ranting

Re:Bugs found in GCC with the help of PVS-Studio by 0xmohit on Saturday September 03, 2016 @06:14AM (#12418604)
> a == 1 || a != 2 needs a warning

Yes, it needs a warning because it's kind of obvious that there is something amiss about this expression. Only the author could tell what was specifically wrong.

Re:Bugs found in GCC with the help of PVS-Studio by raverbashing on Saturday September 03, 2016 @06:33AM (#12418647)
Yes

I would advocate for the maintenance of both expressions if the comparison is tricky

If this is a hot path that must absolutely be optimized then a comment explaining the conditions is needed

And of course, the != 2 question might change (either because of a bug or logic change) but the == 1 might still be valid, however, if you took the first one your change will break the code