]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
CODING_STYLE: allow c99-style mixed code and declarations
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 7 Jun 2018 13:08:02 +0000 (15:08 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Jun 2018 14:42:34 +0000 (16:42 +0200)
We already allowed variables to be declared in the middle of a function
(whenever a new scope was opened), so this isn't such a big change. Sometimes
we would open a scope just to work around this prohibition.

But sometimes the code can be much clearer if the variable is declared
somewhere in the middle of a scope, in particular if the declaration is
combined with initialization or acquisition of some resources. So let's allow
this, but keep things in the old style, unless there's a good reason to move
the variable declaration to a different place.

doc/CODING_STYLE
meson.build

index be303591605647cd6f115a4c35e85cb205814253..2c1577d8aa3770356c3c5c4cf22f7baff5efcc2a 100644 (file)
   applicable (i.e. wherever you just care about equality/inequality, not about
   the sorting order).
 
-- Please do not allocate variables on the stack in the middle of code,
-  even if C99 allows it. Wrong:
+- Preferably allocate stack variables on the top of the block:
 
   {
-          a = 5;
-          int b;
-          b = a;
-  }
+          int a, b;
 
-  Right:
-
-  {
-          int b;
           a = 5;
           b = a;
   }
index 18b4ace5b9744977e17c6c8888d10dd3e65288b4..a4c2368df945fc59034c2b4cc9b7963a3441d9e2 100644 (file)
@@ -302,7 +302,6 @@ possible_cc_flags = [
         '-Wold-style-definition',
         '-Wpointer-arith',
         '-Winit-self',
-        '-Wdeclaration-after-statement',
         '-Wfloat-equal',
         '-Wsuggest-attribute=noreturn',
         '-Werror=missing-prototypes',
@@ -365,7 +364,7 @@ endif
 add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
 
 # "negative" arguments: gcc on purpose does not return an error for "-Wno-"
-# arguments, just emits a warnings. So test for the "positive" version instead.
+# arguments, just emits a warning. So test for the "positive" version instead.
 foreach arg : ['unused-parameter',
                'missing-field-initializers',
                'unused-result',