CODING_STYLE: allow c99-style mixed code and declarations
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.
This commit is contained in:
parent
e02a33c2b7
commit
d40f5cc498
|
@ -105,19 +105,11 @@
|
||||||
applicable (i.e. wherever you just care about equality/inequality, not about
|
applicable (i.e. wherever you just care about equality/inequality, not about
|
||||||
the sorting order).
|
the sorting order).
|
||||||
|
|
||||||
- Please do not allocate variables on the stack in the middle of code,
|
- Preferably allocate stack variables on the top of the block:
|
||||||
even if C99 allows it. Wrong:
|
|
||||||
|
|
||||||
{
|
{
|
||||||
a = 5;
|
int a, b;
|
||||||
int b;
|
|
||||||
b = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
Right:
|
|
||||||
|
|
||||||
{
|
|
||||||
int b;
|
|
||||||
a = 5;
|
a = 5;
|
||||||
b = a;
|
b = a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,7 +302,6 @@ possible_cc_flags = [
|
||||||
'-Wold-style-definition',
|
'-Wold-style-definition',
|
||||||
'-Wpointer-arith',
|
'-Wpointer-arith',
|
||||||
'-Winit-self',
|
'-Winit-self',
|
||||||
'-Wdeclaration-after-statement',
|
|
||||||
'-Wfloat-equal',
|
'-Wfloat-equal',
|
||||||
'-Wsuggest-attribute=noreturn',
|
'-Wsuggest-attribute=noreturn',
|
||||||
'-Werror=missing-prototypes',
|
'-Werror=missing-prototypes',
|
||||||
|
@ -365,7 +364,7 @@ endif
|
||||||
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
|
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
|
||||||
|
|
||||||
# "negative" arguments: gcc on purpose does not return an error for "-Wno-"
|
# "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',
|
foreach arg : ['unused-parameter',
|
||||||
'missing-field-initializers',
|
'missing-field-initializers',
|
||||||
'unused-result',
|
'unused-result',
|
||||||
|
|
Loading…
Reference in New Issue