Sophie

Sophie

distrib > Fedora > 14 > x86_64 > by-pkgid > 6c56f23f3632aee885c74b9d9eae6b45 > files > 60

libcaca-devel-0.99-0.10.beta17.fc14.x86_64.rpm

<!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>
<!-- Generated by Doxygen 1.6.2-20100208 -->
<div class="contents">


<h1><a class="anchor" id="libcaca-style">Libcaca coding style </a></h1><h2><a class="anchor" id="sty1">
General guidelines</a></h2>
<p>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" id="sty2">
C coding style</a></h2>
<p>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 &gt; 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>
<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>);
</pre></div><p>A space can be inserted after keywords such as <code>for</code>, <code>while</code> or <code>if</code>, but consistency with the rest of the page is encouraged:</p>
<div class="fragment"><pre class="fragment"><span class="keywordflow">if</span>(a == b)
    <span class="keywordflow">return</span>;

<span class="keywordflow">if</span> (p == NULL)
</pre></div><p>Do not put parentheses around return values:</p>
<div class="fragment"><pre class="fragment"><span class="keywordflow">return</span> a + (b &amp; 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 &amp; 0x84)
        <span class="keywordflow">return</span> a;

    <span class="keywordflow">if</span>(a &lt; 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" id="sty3">
C++ coding style</a></h2>
<p>Nothing here yet. </p>
</div>
  </body>
</html>