[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/20] CODING_STYLE: Section about conditional statem
From: |
Michael Tokarev |
Subject: |
[Qemu-devel] [PULL 06/20] CODING_STYLE: Section about conditional statement |
Date: |
Fri, 15 Aug 2014 19:14:57 +0400 |
From: Gonglei <address@hidden>
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 <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
CODING_STYLE | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/CODING_STYLE b/CODING_STYLE
index 4280945..d46cfa5 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.
--
1.7.10.4
- [Qemu-devel] [PULL 00/20] Trivial patches for 2014-08-15, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 02/20] memory: Update obsolete comment about AddrRange field type, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 08/20] audio: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 01/20] apic: Fix reported DFR content, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 07/20] usb: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 06/20] CODING_STYLE: Section about conditional statement,
Michael Tokarev <=
- [Qemu-devel] [PULL 13/20] vmxnet3: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 19/20] l2cap: fix access to freed memory, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 14/20] qemu-options.hx: fix typo about l2tpv3, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 16/20] ssi: xilinx_spi: Initialise CS GPIOs as NULL, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 20/20] ivshmem: check the value returned by fstat(), Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 12/20] vl: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 11/20] spice: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 04/20] pci-host: update obsolete reference about piix_pci.c, Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 09/20] isa-bus: don't use 'Yoda conditions', Michael Tokarev, 2014/08/15
- [Qemu-devel] [PULL 03/20] qemu-options.hx: fix a typo of chardev, Michael Tokarev, 2014/08/15