Skip to content

Commit

Permalink
Update the coding standard
Browse files Browse the repository at this point in the history
Issue: eclipse-openj9/openj9#19261
Co-authored-by: Jason Feng <[email protected]>
Co-authored-by: Keith W. Campbell <[email protected]>
Signed-off-by: Amarpreet Singh <[email protected]>
  • Loading branch information
3 people committed Jun 6, 2024
1 parent b198d2e commit 00717e3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions doc/CodingStandard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==).
Expand All @@ -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
Expand Down

0 comments on commit 00717e3

Please sign in to comment.