Skip to main content
deleted 1 character in body
Source Link
gnasher729
  • 47.5k
  • 4
  • 68
  • 133

I always turn on all reasonable warnings in a compiler, and turn warnings into errors, so my code will be free of warnings.

"All reasonable warnings" with one compiler that I use will warn for "if (x = y)" because it might be an unwanted assignment instead of a comparison. It will not warn for "if ((x = y))" - the unusual extra parentheses tell the compiler that this couldcode isn't written that way by accident but intentional, so no warning.

On the other hand, if you want to write this in one line, you can always write "if ((x = y) != 0)" or "if ((x = y) == true)".

I always turn on all reasonable warnings in a compiler, and turn warnings into errors, so my code will be free of warnings.

"All reasonable warnings" with one compiler that I use will warn for "if (x = y)" because it might be an unwanted assignment instead of a comparison. It will not warn for "if ((x = y))" - the unusual extra parentheses tell the compiler that this could isn't written that way by accident but intentional, so no warning.

On the other hand, if you want to write this in one line, you can always write "if ((x = y) != 0)" or "if ((x = y) == true)".

I always turn on all reasonable warnings in a compiler, and turn warnings into errors, so my code will be free of warnings.

"All reasonable warnings" with one compiler that I use will warn for "if (x = y)" because it might be an unwanted assignment instead of a comparison. It will not warn for "if ((x = y))" - the unusual extra parentheses tell the compiler that this code isn't written that way by accident but intentional, so no warning.

On the other hand, if you want to write this in one line, you can always write "if ((x = y) != 0)" or "if ((x = y) == true)".

Source Link
gnasher729
  • 47.5k
  • 4
  • 68
  • 133

I always turn on all reasonable warnings in a compiler, and turn warnings into errors, so my code will be free of warnings.

"All reasonable warnings" with one compiler that I use will warn for "if (x = y)" because it might be an unwanted assignment instead of a comparison. It will not warn for "if ((x = y))" - the unusual extra parentheses tell the compiler that this could isn't written that way by accident but intentional, so no warning.

On the other hand, if you want to write this in one line, you can always write "if ((x = y) != 0)" or "if ((x = y) == true)".