x = y;
}
+Use hanging braces for compound statements: the opening brace of a compound
+statement should be on the same line as the condition being tested. Only
+top-level function bodies, nested scopes, and compound structure declarations
+should ever have { on a line by itself.
+
+ void
+ foo(int a, int b)
+ { // correct - function body
+ int 2d[][] = {
+ { // correct - complex initialization
+ 1, 2,
+ },
+ };
+ if (a)
+ { // BAD: compound brace on its own line
+ do_stuff();
+ }
+ { // correct - nested scope
+ int tmp;
+ if (a < b) { // correct - hanging brace
+ tmp = b;
+ b = a;
+ a = tmp;
+ }
+ }
+ }
+
Preprocessor
============
$(_sc_search_regexp)
sc_curly_braces_style:
- @files=$$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); \
- $(GREP) -nHP \
-'^\s*(?!([a-zA-Z_]*for_?each[a-zA-Z_]*) ?\()([_a-zA-Z0-9]+( [_a-zA-Z0-9]+)* ?\()?(\*?[_a-zA-Z0-9]+(,? \*?[_a-zA-Z0-9\[\]]+)+|void)\) ?\{' \
- $$files && { echo '$(ME): Non-K&R style used for curly' \
- 'braces around function body, see' \
- 'HACKING' 1>&2; exit 1; } || :
+ @files=$$($(VC_LIST_EXCEPT) | grep '\.[ch]$$'); \
+ if $(GREP) -nHP \
+'^\s*(?!([a-zA-Z_]*for_?each[a-zA-Z_]*) ?\()([_a-zA-Z0-9]+( [_a-zA-Z0-9]+)* ?\()?(\*?[_a-zA-Z0-9]+(,? \*?[_a-zA-Z0-9\[\]]+)+|void)\) ?\{' \
+ $$files; then \
+ echo '$(ME): Non-K&R style used for curly braces around' \
+ 'function body, see HACKING' 1>&2; exit 1; \
+ fi; \
+ if $(GREP) -A1 -En ' ((if|for|while|switch) \(|(else|do)\b)[^{]*$$'\
+ $$files | $(GREP) '^[^ ]*- *{'; then \
+ echo '$(ME): Use hanging braces for compound statements,' \
+ 'see HACKING' 1>&2; exit 1; \
+ fi
sc_prohibit_windows_special_chars_in_filename:
@files=$$($(VC_LIST_EXCEPT) | grep '[:*?"<>|]'); \
}
</pre>
+ <p>Use hanging braces for compound statements: the opening brace
+ of a compound statement should be on the same line as the
+ condition being tested. Only top-level function bodies, nested
+ scopes, and compound structure declarations should ever have {
+ on a line by itself.
+ </p>
+
+<pre>
+ void
+ foo(int a, int b)
+ { // correct - function body
+ int 2d[][] = {
+ { // correct - complex initialization
+ 1, 2,
+ },
+ };
+ if (a)
+ { // BAD: compound brace on its own line
+ do_stuff();
+ }
+ { // correct - nested scope
+ int tmp;
+ if (a < b) { // correct - hanging brace
+ tmp = b;
+ b = a;
+ a = tmp;
+ }
+ }
+ }
+</pre>
+
<h2><a name="preprocessor">Preprocessor</a></h2>
<p>Macros defined with an ALL_CAPS name should generally be