<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>libcaca documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> </head> <body> <!-- $Id$ --> <!-- Generated by Doxygen 1.5.9 --> <div class="contents"> <h1><a class="anchor" name="libcaca-style">Libcaca coding style </a></h1><h2><a class="anchor" name="sty1"> General guidelines</a></h2> A pretty safe rule of thumb is: look at what has already been done and try to do the same.<p> <ul> <li>Tabulations should be avoided and replaced with <em>eight</em> spaces.</li><li>Indentation is generally 4 spaces.</li><li>Lines should wrap at most at 79 characters.</li><li>Do not leave whitespace at the end of lines.</li><li>Do not use multiple spaces for anything else than indentation.</li><li>Code qui fait des warnings == code de porc == deux baffes dans ta gueule</li></ul> <h2><a class="anchor" name="sty2"> C coding style</a></h2> Try to use short names whenever possible (<code>i</code> for indices, <code>w</code> for width, <code>cv</code> for canvas...). Macros are always uppercase, variable and function names are always lowercase. Use the underscore to separate words within names:<p> <div class="fragment"><pre class="fragment"><span class="preprocessor">#define BROKEN 0</span> <span class="preprocessor"></span><span class="preprocessor">#define MAX(x, y) ((x > y) ? (x) : (y))</span> <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> x, y, w, h; <span class="keywordtype">char</span> *font_name; <span class="keywordtype">void</span> frobulate_every_three_seconds(<span class="keywordtype">void</span>); </pre></div><p> <code>const</code> is a <em>suffix</em>. It's <code>char</code> <code>const</code> <code>*foo</code>, not <code>const</code> <code>char</code> <code>*foo</code>.<p> Use spaces after commas and between operators. Do not use spaces after an opening parenthesis or before a closing one:<p> <div class="fragment"><pre class="fragment">a += 2; b = (a * (c + d)); x = min(x1, x2, x3); </pre></div><p> Do not put a space between functions and the corresponding opening parenthesis:<p> <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> function(<span class="keywordtype">int</span>); <span class="keywordflow">if</span>(a == b) <span class="keywordflow">return</span>; </pre></div><p> Do not put parentheses around return values:<p> <div class="fragment"><pre class="fragment"><span class="keywordflow">return</span> a + (b & x) + d[10]; </pre></div><p> Opening braces should be on a line of their own, aligned with the current block. Braces are optional for one-liners:<p> <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> function(<span class="keywordtype">int</span> a) { <span class="keywordflow">if</span>(a & 0x84) <span class="keywordflow">return</span> a; <span class="keywordflow">if</span>(a < 0) { <span class="keywordflow">return</span> -a; } <span class="keywordflow">else</span> { a /= 2; <span class="keywordflow">switch</span>(a) { <span class="keywordflow">case</span> 0: <span class="keywordflow">case</span> 1: <span class="keywordflow">return</span> -1; <span class="keywordflow">break</span>; <span class="keywordflow">default</span>: <span class="keywordflow">return</span> a; } } } </pre></div><h2><a class="anchor" name="sty3"> C++ coding style</a></h2> Nothing here yet. </div> <!-- $Id$ --> </body> </html>