qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declarat


From: Paolo Bonzini
Subject: [Qemu-devel] [PATCH] CODING_STYLE: update line length and mixed declaration rules
Date: Fri, 19 Jun 2015 09:29:04 +0200

1) Line lengths above 80 characters do exist.  They are rare, but
they happen from time to time.  An ignored rule is worse than an
exception to the rule, so do the latter.

2) Mixed declarations also do exist at the top of #ifdef blocks.
Remark on this particular usage and suggest an alternative.

Cc: Andreas Faerber <address@hidden>
Cc: Markus Armbruster <address@hidden>
Cc: Eduardo Habkost <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
 CODING_STYLE          | 21 ++++++++++++++++-----
 scripts/checkpatch.pl |  9 ++++++---
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/CODING_STYLE b/CODING_STYLE
index d46cfa5..d013cb8 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -31,7 +31,11 @@ Do not leave whitespace dangling off the ends of lines.
 
 2. Line width
 
-Lines are 80 characters; not longer.
+Lines should be 80 characters; try not to make them longer.
+
+Sometimes it is hard to do, especially when dealing with QEMU subsystems
+that use long function or symbol names.  Even in that case, do not make
+lines _much_ longer than 80 characters.
 
 Rationale:
  - Some people like to tile their 24" screens with a 6x4 matrix of 80x24
@@ -39,6 +43,8 @@ Rationale:
    let them keep doing it.
  - Code and especially patches is much more readable if limited to a sane
    line length.  Eighty is traditional.
+ - The four-space indentation makes the most common excuse ("But look
+   at all that white space on the left!") moot.
  - It is the QEMU coding style.
 
 3. Naming
@@ -87,10 +93,15 @@ Furthermore, it is the QEMU coding style.
 
 5. Declarations
 
-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.
+Mixed declarations (interleaving statements and declarations within
+blocks) are generally not allowed; declarations should be at the beginning
+of blocks.
+
+Every now and then, an exception is made for declarations inside a
+#ifdef or #ifndef block: if the code looks nicer, such declarations can
+be placed at the top of the block even if there are statements above.
+On the other hand, however, it's often best to move that #ifdef/#ifndef
+block to a separate function altogether.
 
 6. Conditional statements
 
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7f0aae9..f4e7050 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1470,10 +1470,13 @@ sub process {
                if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
                    $rawline !~ /address@hidden/ &&
                    !($line =~ 
/^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/
 ||
-                   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
-                   $length > 80)
+                   $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/))
                {
-                       WARN("line over 80 characters\n" . $herecurr);
+                       if ($length > 90) {
+                               ERROR("line over 90 characters\n" . $herecurr);
+                       } if ($length > 80) {
+                               WARN("line over 80 characters\n" . $herecurr);
+                       }
                }
 
 # check for spaces before a quoted newline
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]