diff --git a/doc/CodingStandard.md b/doc/CodingStandard.md index fd9a7899ed6..55a0dcbed23 100644 --- a/doc/CodingStandard.md +++ b/doc/CodingStandard.md @@ -412,6 +412,21 @@ if (NULL != myPointer) { } ``` +* When comparing a value with two other values with <, <=, >, or >= utilize the following format: + +```c +if ((0 <= logLevelValue) && (logLevelValue <= 4)) { +``` + +Correct +```c +if ((0 <= logLevelValue) && (logLevelValue <= 4)) { +``` + +Wrong +```c +if ((logLevelValue >= 0) && (logLevelValue <= 4)) { +``` #### Rationale * Keeping rvalues on the left can prevent accidental assignment (= vs ==). @@ -421,6 +436,7 @@ if (NULL != myPointer) { * The ") {" sequence provides a clear visual indication that the condition has ended and the block has begun. * C order of operation rules are complicated; avoid confusion and mistakes by using parentheses to make the order explicit. * Combining assignment and tests violates the "Try to do only one thing on each line of code" principle. +* It seems that when comparing a value with two other values as ((min <= value) && (value <= max)), it is clearer. ### Parameter passing