网页 综合 更新时间 2026-11-14 09:11:08

Apache Developers' C Language Style Guide - The Apache HTTP Server Project

自动蜘蛛 httpd.apache.org 正文约 3253 字
Compiled by Paul Sutton paul@awe.com. Based on a vote taken in November, 1996. Further refinements voted upon in July 1997.
[This bit could state that code should be laid out to be clear to someone else familiar with Apache. Functions should be short and easily understood. Comments should be provided to explain the rationale for code which is not obvious, and to document behavior of functions. The guidelines can be broken if necessary to achieve a clearer layout]
This style can be generated with the following arguments to GNU indent:
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.
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.
Provide comments which explain the function of code where it is not clear from the code itself. Provide rationale where necessary for particular bits of code.
Comments should be indented to same level as the surrounding text.
Functions are laid out as follows:
The return type is placed on the same line as the function. Arguments (if any) are given in ANSI style. If no arguments, declare function as void. No space between function name and opening bracket, single space after comma separating each argument. The opening brace is placed on the line after the definition, indented to line up with the start of the return type text. The code is indented with four spaces, and the closing brace is indented to line up with the opening brace. Also see the section on indenting long declarations and invocations.
Space after commas in function calls. No space between function name and opening bracket.
Also see the section on indenting long declarations and invocations.
Flow-control statements (if, while, for, etc.) are laid out as in this
There is a space between the keyword and the opening bracket. Opening brace placed on same line as the flow keyword. The code itself is indented by four spaces. The closing brace is indented to line up with the opening brace. If an else clause is used, the else keyword is placed on the line following the closing brace and is indented to line up with the corresponding if. Also see the section on indenting long expressions.
Space after the semi-colons.
case lines within a switch() are indented to same level as the switch statement itself. The code for each case is indented by four spaces. Braces are laid out as for other control-flow keywords.
Space before and after assignment and other and operators. No space between unary operators (increment, decrement, and negation) and the lvalue.
Copyright © 1997-2026 The Apache Software Foundation. Apache HTTP Server, Apache, the Apache logo and the Apache HTTP Server logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.
访问原文 返回搜索 https://httpd.apache.org/dev/styleguide.html
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。