mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Merge pull request #365 from kkeri/master
Replacing problematic code example in ES.41
This commit is contained in:
commit
ff7bc575e8
|
@ -8412,13 +8412,14 @@ Avoid errors. Readability. Not everyone has the operator table memorized.
|
||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
if (a && b == 1) // OK?
|
const unsigned int flag = 2;
|
||||||
if (a & b == 1) // OK?
|
unsigned int a = flag;
|
||||||
|
|
||||||
|
if (a & flag != 0) // bad: means a&(flag != 0)
|
||||||
|
|
||||||
Note: We recommend that programmers know their precedence table for the arithmetic operations, the logical operations, but consider mixing bitwise logical operations with other operators in need of parentheses.
|
Note: We recommend that programmers know their precedence table for the arithmetic operations, the logical operations, but consider mixing bitwise logical operations with other operators in need of parentheses.
|
||||||
|
|
||||||
if (a && b == 1) // OK: means a&&(b == 1)
|
if ((a & flag) != 0) // OK: works as intended
|
||||||
if (a & b == 1) // bad: means (a&b) == 1
|
|
||||||
|
|
||||||
##### Note
|
##### Note
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user