Adopted paren-cond ternary operator style

So:

  x = (cond) ? yes : no;

Where there are always parentheses around the condition, even if not
required for disambiguity. Additional parentheses are always allowed,
but the parenthesized condition helps signal that a ternary operator is
coming earlier in the expression.

This style has grown on me as I think it helps code readability. It
reminds me of the required parentheses for if/while statements.

Might as well adopt codebase-wide.
This commit is contained in:
Christopher Haster
2024-01-20 21:40:00 -06:00
parent 76715ced4a
commit 6fc040db1a
10 changed files with 286 additions and 282 deletions
+3 -3
View File
@@ -165,7 +165,7 @@ code = '''
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t traversal = LFSR_TRAVERSAL(
VALIDATE ? LFSR_TRAVERSAL_VALIDATE : 0);
(VALIDATE) ? LFSR_TRAVERSAL_VALIDATE : 0);
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
assert(i < 2*BLOCK_COUNT);
@@ -325,7 +325,7 @@ code = '''
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t traversal = LFSR_TRAVERSAL(
(VALIDATE ? LFSR_TRAVERSAL_VALIDATE : 0)
((VALIDATE) ? LFSR_TRAVERSAL_VALIDATE : 0)
| LFSR_TRAVERSAL_ALL);
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops
@@ -473,7 +473,7 @@ code = '''
memset(seen, 0, (BLOCK_COUNT+7)/8);
lfsr_traversal_t traversal = LFSR_TRAVERSAL(
(VALIDATE ? LFSR_TRAVERSAL_VALIDATE : 0)
((VALIDATE) ? LFSR_TRAVERSAL_VALIDATE : 0)
| LFSR_TRAVERSAL_ALL);
for (lfs_block_t i = 0;; i++) {
// a bit hacky, but this catches infinite loops