mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
ES.87 (redundant ==
or !=
) Add my_condition == true
example
Code like `if (my_condition == true)` does occasionally occur "in the wild", so it seems worth adding this as an example.
This commit is contained in:
parent
5c1a2b69fb
commit
b039e7a7ba
|
@ -13281,6 +13281,10 @@ Helps make style consistent and conventional.
|
|||
By definition, a condition in an `if`-statement, `while`-statement, or a `for`-statement selects between `true` and `false`.
|
||||
A numeric value is compared to `0` and a pointer value to `nullptr`.
|
||||
|
||||
// Assuming that "my_condition" is a `bool` variable
|
||||
if (my_condition) { ... } // good
|
||||
if (my_condition == true) { ... } // redundant ==true, not recommended
|
||||
|
||||
// These all mean "if p is not nullptr"
|
||||
if (p) { ... } // good
|
||||
if (p != 0) { ... } // redundant !=0, bad: don't use 0 for pointers
|
||||
|
|
Loading…
Reference in New Issue
Block a user