coar97/08/01 13:08:51
Modified:. styleguide.html
Log:
Update style guide with the majority results from the most
recent issue vote.
Revision ChangesPath
1.4 +100 -46 apache-devsite/styleguide.html
Index: styleguide.html
===
RCS file: /export/home/cvs/apache-devsite/styleguide.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- styleguide.html 1997/07/16 10:15:48 1.3
+++ styleguide.html 1997/08/01 20:08:49 1.4
@@ -4,9 +4,11 @@
Apache Developers' C Language Style Guide
-Compiled by Paul Sutton mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]. Based on a vote
+Compiled by Paul Sutton mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]. Based on a
vote
taken in November, 1996.
+
+Further refinements voted upon in July 1997.
@@ -24,42 +26,55 @@
-i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1
The Guidelines
+
+ Opening braces are given on the same lines as statements, or on the
+following line at the start of a function definition.
+
+ Code inside a block (whether surrounded by braces or not) is
+indented by four space characters. Tab characters are not
+used. Comments are indented to the same level as the surrounding
+code.
+
+ Closing braces are always on a separate line from surrounding
+code, and are indented to line up with the start of the text on
+the line containing the corresponding opening brace.
+
+ Functions are declared with ANSI-style arguments.
+
+ There is no space between the function name and the opening bracket
+of the arguments to the function. There is a single space following
+commas in argument lists and the semi-colons in for statements.
+
+ Inside a switch() statement, the case
+keywords are indented to the same level as the switch line.
+
+ Operators in expressions should be surrounded by a single space
+before and after, except for unary increment (++), decrement (--), and
+negation (!) operators.
+
+ There is no whitespace between a cast and the item modified
+(e.g., "(int)j" and not
+"(int) j").
+
+ If a cast is to a pointer type, there is a space between the type
+and the * character (e.g.,
+"(char *)i" instead of
+"(char*)i")
+
+
-Opening braces are given on the same lines as statements, or on the
- following line at the start of a function definition.
-
-Code inside a block (whether surrounded by braces or not) is
- indented by four space characters. Tab characters are not
- used. Comments are indented to the same level as the surrounding
- code.
-
-Closing braces are always on a separate line from surrounding
- code, and are indented to line up with the start of the text on
- the line containing the corresponding opening brace.
-
-Functions are declared with ANSI-style arguments.
-
-Inside a switch() statement, the "case" keywords are indented to
- the same level as the "switch" line.
-
-There is no space between the function name and the opening bracket
- of the arguments to the function. There is a single space following
- commas in argument lists and the semi-colons in for statements.
-
-Operators in expressions should be surrounded by a single space
- before and after, except for increment and decrement operators.
Details and Examples
-Indentation, General Style
+Indentation, General Style
Each level of indentation of code is four spaces. Tab characters
should never be used. Specific indentation rules for function
declarations and control-flow keywords are given below.
Example:
-
+
main(int argc, char **argc)
{
if (argc != 0) {
@@ -68,8 +83,31 @@
}
exit(0);
}
-
-Comments
+
+
+If an expression (or a routine declaration or
+invocation) would extend
+past column 80, the terms or arguments are wrapped at a convenient spot
+and the wrapped portion is indented under the first term in the expression
+(or the first argument to the function).
+Conditional expressions should be wrapped to keep single or
+parenthesized terms as atomic as possible, and place Boolean operators
+at either the start (preferable) or end of the line.
+
+
+Example:
+
+
+ static const char *really_long_name(int i, int j,
+ const char *args, void *foo,
+ int k)
+
+ if (cond1 && (item2 || item3) && (!item4)
+ && (item5 || item6) && item7) {
+ do_a_thing();
+ }
+
+Comments
Provide comments which explain the function of code where it is not
clear from the code itself. Pro