syzygy wrote:bob wrote:I only do them to suppress warnings. Not because I like the style. I've tried for years to keep warnings out. I've pretty well succeeded, although it seems new warnings come with each new compiler release.
Ok, good point as far as it concerns A || B && C type expressions (I didn't really try, but I immediately believe that those generate gcc warnings without parentheses), but I'm pretty sure some other parentheses can be removed without causing warnings:
Code: Select all
if ((twtm && EnPassant(0) && (PcOnSq(EnPassant(0) + 8) != -pawn)
&& (PcOnSq(EnPassant(0) - 7) != pawn)
&& (PcOnSq(EnPassant(0) - 9) != pawn)) || (Flip(twtm)
&& EnPassant(0)
&& (PcOnSq(EnPassant(0) - 8) != pawn)
&& (PcOnSq(EnPassant(0) + 7) != -pawn)
&& (PcOnSq(EnPassant(0) + 9) != -pawn))) {
There is no doubt that != takes precedence over &&.
Code: Select all
if (!Attacks(tree, to, enemy)
&& (directions[from][to] != check_direction1)
&& (directions[from][to] != check_direction2))
Same remark.
The false assumption you have is that the code was written like that from the beginning. Most likely not. It has evolved over almost 20 years now, and once a pair of parens is "in" they rarely come "out" because that is a good way to introduce bugs I don't want to deal with.
Whether the above were originally written as shown, or whether the tests were rewritten multiple times, I can't say, and I don't really see any good reason to try to trace them back to the earliest version I have, since I don't have the first 2-3 years worth of versions anyway. I will probably fix the last one above in any case since I don't really like the way it reads...
BTW, the last statement I found in GenerateCheckEvasions(), but I can't find the first example. Where, exactly, is that, if you remember?
I have rewritten/cleaned up a LOT of code in the current version (24.0) so it might be long gone, of course.