summaryrefslogtreecommitdiff
path: root/CODING_STYLE
diff options
context:
space:
mode:
authorGonglei <arei.gonglei@huawei.com>2014-08-11 21:00:51 +0800
committerMichael Tokarev <mjt@tls.msk.ru>2014-08-15 18:54:06 +0400
commit2bb0020cf97c938f8339c76fa8a0da6353e8d27e (patch)
tree86c6427b2cbcb61e357da559630f2f1fdc5e2bdc /CODING_STYLE
parent30dc600bbfe2c927440fd611d585d7a2acb42fbf (diff)
CODING_STYLE: Section about conditional statement
Yoda conditions lack readability, and QEMU has a strict compiler configuration for checking a common mistake like "if (dev = NULL)". Make it a written rule. Signed-off-by: Gonglei <arei.gonglei@huawei.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
Diffstat (limited to 'CODING_STYLE')
-rw-r--r--CODING_STYLE14
1 files changed, 14 insertions, 0 deletions
diff --git a/CODING_STYLE b/CODING_STYLE
index 4280945ff0..d46cfa5f65 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -91,3 +91,17 @@ Mixed declarations (interleaving statements and declarations within blocks)
are not allowed; declarations should be at the beginning of blocks. In other
words, the code should not generate warnings if using GCC's
-Wdeclaration-after-statement option.
+
+6. Conditional statements
+
+When comparing a variable for (in)equality with a constant, list the
+constant on the right, as in:
+
+if (a == 1) {
+ /* Reads like: "If a equals 1" */
+ do_something();
+}
+
+Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read.
+Besides, good compilers already warn users when '==' is mis-typed as '=',
+even when the constant is on the right.