Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../server/data/WWW/manual.neu/styleguide.html
Real path: /www/server/data/WWW/manual.neu/styleguide.html
Zurück
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <link href="/css/apsite.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> <meta name="author" content="Documentation Group" /><meta name="email" content="docs@httpd.apache.org" /> <title>Apache Developers' C Language Style Guide - The Apache HTTP Server Project</title> </head> <body> <div id="page-header"> <p class="menu"> </p> <p class="apache"> </p> <a href="/"> <img alt="" width="800" height="72" src="/images/httpd_logo_wide_new.png" /> </a> </div> <!-- LEFT SIDE NAVIGATION --> <div id="apmenu"> <h1 id="essentials">Essentials</h1> <ul> <li><a href="/ABOUT_APACHE.html">About</a></li> <li><a href="http://www.apache.org/licenses/">License</a></li> <li><a href="http://wiki.apache.org/httpd/FAQ">FAQ</a></li> <li><a href="/security_report.html">Security Reports</a></li> </ul> <h1 id="downloading">Download!</h1> <ul> <li><a href="/download.cgi">From a Mirror</a></li> </ul> <h1 id="documentation"><a href="/docs/">Documentation</a></h1> <ul> <li><a href="/docs/2.4/">Version 2.4</a></li> <li><a href="/docs/2.2/">Version 2.2</a></li> <li><a href="/docs/2.0/">Version 2.0</a></li> <li><a href="/docs/trunk/">Trunk (dev)</a></li> <li><a href="http://wiki.apache.org/httpd/">Wiki</a></li> </ul> <h1 id="get-support">Get Support</h1> <ul> <li><a href="/support.html">Support</a></li> </ul> <h1 id="get-involved">Get Involved</h1> <ul> <li><a href="/lists.html">Mailing Lists</a></li> <li><a href="/bug_report.html">Bug Reports</a></li> <li><a href="/dev/">Developer Info</a></li> </ul> <h1 id="subprojects">Subprojects</h1> <ul> <li><a href="/docs-project/">Docs</a></li> <li><a href="/test/">Test</a></li> <li><a href="/test/flood/">Flood</a></li> <li><a href="/apreq/">libapreq</a></li> <li><a href="/modules">Modules</a></li> <li><a href="/mod_fcgid/">mod_fcgid</a></li> <li><a href="/mod_ftp/">mod_ftp</a></li> </ul> <h1 id="miscellaneous"><a href="/info/">Miscellaneous</a></h1> <ul> <li><a href="/contributors/">Contributors</a></li> <li><a href="http://www.apache.org/foundation/thanks.html">Sponsors</a></li> <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> </ul> </div> <!-- RIGHT SIDE INFORMATION --> <div id="apcontents"> <h1 id="apache-developers-c-language-style-guide">Apache Developers' C Language Style Guide</h1> <p><strong>Compiled by Paul Sutton <a href="mailto:paul@awe.com">paul@awe.com</a> </strong>. Based on a vote taken in November, 1996.<br></br>Further refinements voted upon in July 1997.</p> <h1 id="introduction">Introduction</h1> <p>[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]</p> <p>This style can be generated with the following arguments to GNU indent:</p> <div class="codehilite"><pre><span class="o">-</span><span class="n">i4</span> <span class="o">-</span><span class="n">npsl</span> <span class="o">-</span><span class="n">di0</span> <span class="o">-</span><span class="n">br</span> <span class="o">-</span><span class="n">nce</span> <span class="o">-</span><span class="n">d0</span> <span class="o">-</span><span class="n">cli0</span> <span class="o">-</span><span class="n">npcs</span> <span class="o">-</span><span class="n">nfc1</span> <span class="o">-</span><span class="n">nut</span> </pre></div> <h1 id="the-guidelines">The Guidelines</h1> <ul> <li>Opening braces are given on the same lines as statements, or on the following line at the start of a function definition.</li> <li>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.</li> <li>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.</li> <li>Functions are declared with ANSI-style arguments.</li> <li>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.</li> <li>Inside a <code>switch()</code> statement, the <code>case</code> keywords are indented to the same level as the <code>switch</code> line.</li> <li>Operators in expressions should be surrounded by a single space before and after, except for unary increment (++), decrement (--), and negation (!) operators.</li> <li>There is no whitespace between a cast and the item modified (<EM>e.g.</EM>, "<samp>(int)j</samp>" and not "<samp>(int) j</samp>").</li> <li>If a cast is to a pointer type, there is a space between the type and the <code>*</code> character (<em>e.g.</em>, "<code>(char *)i</code>" instead of "<code>(char*)i</code>")</li> </ul> <h1 id="details-and-examples">Details and Examples</h1> <h2 id="indentation-general-style"><strong>Indentation, General Style</strong></h2> <p>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.</p> <p>Example:</p> <div class="codehilite"><pre><span class="n">main</span><span class="p">(</span><span class="nb">int</span> <span class="n">argc</span><span class="p">,</span> <span class="n">char</span> <span class="o">**</span><span class="n">argc</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> <span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"No arguments allowed\n"</span><span class="p">);</span> <span class="nb">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span> <span class="p">}</span> <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> <span class="p">}</span> </pre></div> <p><A NAME="long-exps">If an expression</A> (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.</p> <p>Example:</p> <div class="codehilite"><pre> <span class="n">static</span> <span class="n">const</span> <span class="n">char</span> <span class="o">*</span><span class="n">really_long_name</span><span class="p">(</span><span class="nb">int</span> <span class="n">i</span><span class="p">,</span> <span class="nb">int</span> <span class="n">j</span><span class="p">,</span> <span class="n">const</span> <span class="n">char</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">void</span> <span class="o">*</span><span class="n">foo</span><span class="p">,</span> <span class="nb">int</span> <span class="n">k</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="n">cond1</span> <span class="o">&&</span> <span class="p">(</span><span class="n">item2</span> <span class="o">||</span> <span class="n">item3</span><span class="p">)</span> <span class="o">&&</span> <span class="p">(</span><span class="o">!</span><span class="n">item4</span><span class="p">)</span> <span class="o">&&</span> <span class="p">(</span><span class="n">item5</span> <span class="o">||</span> <span class="n">item6</span><span class="p">)</span> <span class="o">&&</span> <span class="n">item7</span><span class="p">)</span> <span class="p">{</span> <span class="n">do_a_thing</span><span class="p">();</span> <span class="p">}</span> </pre></div> <h2 id="comments"><strong>Comments</strong></h2> <p>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.</p> <p>Comments should be indented to same level as the surrounding text.</p> <p>Example:</p> <div class="codehilite"><pre><span class="n">code</span><span class="p">;</span> <span class="sr">/* comment */</span> <span class="n">code</span><span class="p">;</span> </pre></div> <h2 id="function-declaration-and-layout"><strong>Function Declaration and Layout</strong></h2> <p>Functions are laid out as follows:</p> <p>Example:</p> <div class="codehilite"><pre><span class="nb">int</span> <span class="n">main</span><span class="p">(</span><span class="nb">int</span> <span class="n">argc</span><span class="p">,</span> <span class="n">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span> <span class="n">code</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>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 <code>void</code>. 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. <strong>Also see the section on indenting <A HREF="#long-exps">long declarations and invocations</A>.</strong> </p> <h2 id="function-calls"><strong>Function Calls</strong></h2> <p>Space after commas in function calls. No space between function name and opening bracket.</p> <p>Example:</p> <div class="codehilite"><pre><span class="n">f</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">);</span> </pre></div> <p><strong>Also see the section on indenting <A HREF="#long-exps">long declarations and invocations</A>.</strong> </p> <h2 id="flow-control-layout"><strong>Flow-Control Layout</strong></h2> <p>Flow-control statements (<code>if</code>, <code>while</code>, <code>for</code>, <em>etc.</em>) are laid out as in this</p> <p>Example:</p> <div class="codehilite"><pre><span class="k">if</span> <span class="p">(</span><span class="n">expr</span><span class="p">)</span> <span class="p">{</span> <span class="n">code</span><span class="p">;</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="n">code</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>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 <code>else</code> clause is used, the <code>else</code> keyword is placed on the line following the closing brace and is indented to line up with the corresponding <code>if</code>. <strong>Also see the section on indenting <A HREF="#long-exps">long expressions</A>.</strong> </p> <h2 id="for-layout"><strong><code>for</code> Layout</strong></h2> <p>Space after the semi-colons.</p> <p>Example:</p> <div class="codehilite"><pre><span class="k">for</span> <span class="p">(</span><span class="n">a</span><span class="p">;</span> <span class="n">b</span><span class="p">;</span> <span class="n">c</span><span class="p">)</span> </pre></div> <h2 id="switch-layout"><strong><code>switch</code> Layout</strong></h2> <p><code>case</code> lines within a <code>switch()</code> 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.</p> <p>Example:</p> <div class="codehilite"><pre><span class="n">switch</span> <span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="p">{</span> <span class="k">case</span> <span class="n">a:</span> <span class="n">code</span><span class="p">;</span> <span class="k">case</span> <span class="n">b:</span> <span class="n">code</span><span class="p">;</span> <span class="p">}</span> </pre></div> <h2 id="expressions"><strong>Expressions</strong></h2> <p>Space before and after assignment and other and operators. No space between unary operators (increment, decrement, and negation) and the lvalue.</p> <p>Examples:</p> <div class="codehilite"><pre><span class="n">a</span> <span class="o">=</span> <span class="n">b</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span> <span class="n">a</span> <span class="o"><</span> <span class="n">b</span> <span class="n">a</span> <span class="o">=</span> <span class="o">-</span><span class="n">b</span> <span class="n">a</span> <span class="o">=</span> <span class="o">!</span><span class="n">b</span> <span class="o">++</span><span class="n">a</span> </pre></div> <h2 id="capitalisation-of-enums"><strong>Capitalisation of Enums</strong></h2> <p>No rule.</p> <!-- FOOTER --> <div id="footer"> <p>Copyright © 2012 The Apache Software Foundation.<br /> Apache HTTP Server, Apache, and the Apache feather logo are trademarks of The Apache Software Foundation.</p> </div> </div> </body> </html>