CINXE.COM
Code style
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Code style</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <link rel="stylesheet" type="text/css" href="/curl.css"> <link rel="shortcut icon" href="/favicon.ico"> <link rel="icon" href="/logo/curl-symbol.svg" type="image/svg+xml"> <link rel="alternate" type="application/rss+xml" title="cURL Releases" href="https://github.com/curl/curl/releases.atom"> <style type="text/css"> div.sourceCode { background-color: #f0f0f0; padding: 4px 8px 4px 4px; } </style> </head> <body> <div class="main"> <div class="menu"> <div class="dropdown"> <a class="dropbtn" href="/dev/">Dev-related docs</a> <div class="dropdown-content"> <a href="/dev/code-review.html">Code Review</a> <a href="/dev/code-style.html">Code Style</a> <a href="/dev/contribute.html">Contribute</a> <a href="/dev/deprecate.html">Deprecate</a> <a href="/dev/internals.html">Internals</a> <a href="/dev/new-protocol.html">New protocol</a> <a href="/dev/release-procedure.html">Release procedure</a> <a href="/dev/roadmap.html">Roadmap</a> <a href="/dev/runtests.html">Run tests</a> <a href="/dev/source.html">Source code</a> <a href="/rfc/">Specifications</a> <a href="https://testclutch.curl.se/">Test Clutch</a> <a href="/dev/testcurl.html">Test curl</a> <a href="/dev/test-fileformat.html">Test case file format</a> <a href="/dev/tests-overview.html">Tests Overview</a> <a href="/dev/vuln-disclosure.html">Vulnerability Disclosure Policy</a> </div> </div> <div class="dropdown"> <a class="dropbtn" href="/dev/./">Current status</a> <div class="dropdown-content"> <a href="/dev/builds.html">Autobuilds</a> <a href="/snapshots/">Daily snapshots</a> <a href="/dashboard.html">Dashboard</a> <a href="/dev/feature-window.html">Feature window</a> <a href="/gitstats/">git stats</a> <a href="https://github.com/curl/curl/issues" target="_blank">Issues (github)</a> <a href="https://github.com/curl/curl/pulls" target="_blank">Pull requests (github)</a> <a href="/dev/release-notes.html">Release Notes</a> </div> </div> </div> <div class="contents"> <div class="where"><a href="/">curl</a> / <a href="/dev/">Development</a> / <b>code style</b></div> <div class="relatedbox"> <b>Related:</b> <br><a href="code-review.html">Code review</a> <br><a href="contribute.html">Contribute</a> <br><a href="/mail/">Mailing Lists</a> <br><a href="internals.html">Internals</a> </div> <!-- Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. SPDX-License-Identifier: curl --> <h1 id="curl-c-code-style">curl C code style</h1> <p>Source code that has a common style is easier to read than code that uses different styles in different places. It helps making the code feel like one single code base. Easy-to-read is an important property of code and helps making it easier to review when new things are added and it helps debugging code when developers are trying to figure out why things go wrong. A unified style is more important than individual contributors having their own personal tastes satisfied.</p> <p>Our C code has a few style rules. Most of them are verified and upheld by the <code>scripts/checksrc.pl</code> script. Invoked with <code>make checksrc</code> or even by default by the build system when built after <code>./configure --enable-debug</code> has been used.</p> <p>It is normally not a problem for anyone to follow the guidelines, as you just need to copy the style already used in the source code and there are no particularly unusual rules in our set of rules.</p> <p>We also work hard on writing code that are warning-free on all the major platforms and in general on as many platforms as possible. Code that obviously causes warnings is not accepted as-is.</p> <h2 id="naming">Naming</h2> <p>Try using a non-confusing naming scheme for your new functions and variable names. It does not necessarily have to mean that you should use the same as in other places of the code, just that the names should be logical, understandable and be named according to what they are used for. File-local functions should be made static. We like lower case names.</p> <p>See the <a href="https://curl.se/dev/internals.html#symbols">INTERNALS</a> document on how we name non-exported library-global symbols.</p> <h2 id="indenting">Indenting</h2> <p>We use only spaces for indentation, never TABs. We use two spaces for each new open brace.</p> <div class="sourceCode" id="cb1"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>something_is_true<span class="op">)</span> <span class="op">{</span></span> <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span><span class="op">(</span>second_statement <span class="op">==</span> fine<span class="op">)</span> <span class="op">{</span></span> <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> moo<span class="op">();</span></span> <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="op">}</span></span> <span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="comments">Comments</h2> <p>Since we write C89 code, <strong>//</strong> comments are not allowed. They were not introduced in the C standard until C99. We use only <strong>/* comments */</strong>.</p> <div class="sourceCode" id="cb2"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="co">/* this is a comment */</span></span></code></pre></div> <h2 id="long-lines">Long lines</h2> <p>Source code in curl may never be wider than 79 columns and there are two reasons for maintaining this even in the modern era of large and high resolution screens:</p> <ol type="1"> <li><p>Narrower columns are easier to read than wide ones. There is a reason newspapers have used columns for decades or centuries.</p></li> <li><p>Narrower columns allow developers to easier show multiple pieces of code next to each other in different windows. It allows two or three source code windows next to each other on the same screen - as well as multiple terminal and debugging windows.</p></li> </ol> <h2 id="braces">Braces</h2> <p>In if/while/do/for expressions, we write the open brace on the same line as the keyword and we then set the closing brace on the same indentation level as the initial keyword. Like this:</p> <div class="sourceCode" id="cb3"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>age <span class="op"><</span> <span class="dv">40</span><span class="op">)</span> <span class="op">{</span></span> <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co">/* clearly a youngster */</span></span> <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <p>You may omit the braces if they would contain only a one-line statement:</p> <div class="sourceCode" id="cb4"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(!</span>x<span class="op">)</span></span> <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">continue</span><span class="op">;</span></span></code></pre></div> <p>For functions the opening brace should be on a separate line:</p> <div class="sourceCode" id="cb5"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> main<span class="op">(</span><span class="dt">int</span> argc<span class="op">,</span> <span class="dt">char</span> <span class="op">**</span>argv<span class="op">)</span></span> <span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span> <span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="dv">1</span><span class="op">;</span></span> <span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="else-on-the-following-line">'else' on the following line</h2> <p>When adding an <strong>else</strong> clause to a conditional expression using braces, we add it on a new line after the closing brace. Like this:</p> <div class="sourceCode" id="cb6"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>age <span class="op"><</span> <span class="dv">40</span><span class="op">)</span> <span class="op">{</span></span> <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="co">/* clearly a youngster */</span></span> <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span> <span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span> <span class="op">{</span></span> <span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> <span class="co">/* probably grumpy */</span></span> <span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="no-space-before-parentheses">No space before parentheses</h2> <p>When writing expressions using if/while/do/for, there shall be no space between the keyword and the open parenthesis. Like this:</p> <div class="sourceCode" id="cb7"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span><span class="op">(</span><span class="dv">1</span><span class="op">)</span> <span class="op">{</span></span> <span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> <span class="co">/* loop forever */</span></span> <span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="use-boolean-conditions">Use boolean conditions</h2> <p>Rather than test a conditional value such as a bool against TRUE or FALSE, a pointer against NULL or != NULL and an int against zero or not zero in if/while conditions we prefer:</p> <div class="sourceCode" id="cb8"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>result <span class="op">=</span> do_something<span class="op">();</span></span> <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(!</span>result<span class="op">)</span> <span class="op">{</span></span> <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="co">/* something went wrong */</span></span> <span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> result<span class="op">;</span></span> <span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="no-assignments-in-conditions">No assignments in conditions</h2> <p>To increase readability and reduce complexity of conditionals, we avoid assigning variables within if/while conditions. We frown upon this style:</p> <div class="sourceCode" id="cb9"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">((</span>ptr <span class="op">=</span> malloc<span class="op">(</span><span class="dv">100</span><span class="op">))</span> <span class="op">==</span> NULL<span class="op">)</span></span> <span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> NULL<span class="op">;</span></span></code></pre></div> <p>and instead we encourage the above version to be spelled out more clearly:</p> <div class="sourceCode" id="cb10"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>ptr <span class="op">=</span> malloc<span class="op">(</span><span class="dv">100</span><span class="op">);</span></span> <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(!</span>ptr<span class="op">)</span></span> <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> NULL<span class="op">;</span></span></code></pre></div> <h2 id="new-block-on-a-new-line">New block on a new line</h2> <p>We never write multiple statements on the same source line, even for short if() conditions.</p> <div class="sourceCode" id="cb11"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>a<span class="op">)</span></span> <span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> TRUE<span class="op">;</span></span> <span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span> <span class="cf">if</span><span class="op">(</span>b<span class="op">)</span></span> <span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> FALSE<span class="op">;</span></span></code></pre></div> <p>and NEVER:</p> <div class="sourceCode" id="cb12"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>a<span class="op">)</span> <span class="cf">return</span> TRUE<span class="op">;</span></span> <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span> <span class="cf">if</span><span class="op">(</span>b<span class="op">)</span> <span class="cf">return</span> FALSE<span class="op">;</span></span></code></pre></div> <h2 id="space-around-operators">Space around operators</h2> <p>Please use spaces on both sides of operators in C expressions. Postfix <strong>(), [], ->, ., ++, --</strong> and Unary <strong>+, -, !, ~, &</strong> operators excluded they should have no space.</p> <p>Examples:</p> <div class="sourceCode" id="cb13"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>bla <span class="op">=</span> func<span class="op">();</span></span> <span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>who <span class="op">=</span> name<span class="op">[</span><span class="dv">0</span><span class="op">];</span></span> <span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a>age <span class="op">+=</span> <span class="dv">1</span><span class="op">;</span></span> <span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a>true <span class="op">=</span> <span class="op">!</span>false<span class="op">;</span></span> <span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a>size <span class="op">+=</span> <span class="op">-</span><span class="dv">2</span> <span class="op">+</span> <span class="dv">3</span> <span class="op">*</span> <span class="op">(</span>a <span class="op">+</span> b<span class="op">);</span></span> <span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a>ptr<span class="op">-></span>member <span class="op">=</span> a<span class="op">++;</span></span> <span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a><span class="kw">struct</span><span class="op">.</span>field <span class="op">=</span> b<span class="op">--;</span></span> <span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a>ptr <span class="op">=</span> <span class="op">&</span>address<span class="op">;</span></span> <span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a>contents <span class="op">=</span> <span class="op">*</span>pointer<span class="op">;</span></span> <span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a>complement <span class="op">=</span> <span class="op">~</span>bits<span class="op">;</span></span> <span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a>empty <span class="op">=</span> <span class="op">(!*</span>string<span class="op">)</span> <span class="op">?</span> TRUE <span class="op">:</span> FALSE<span class="op">;</span></span></code></pre></div> <h2 id="no-parentheses-for-return-values">No parentheses for return values</h2> <p>We use the 'return' statement without extra parentheses around the value:</p> <div class="sourceCode" id="cb14"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> works<span class="op">(</span><span class="dt">void</span><span class="op">)</span></span> <span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span> <span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> TRUE<span class="op">;</span></span> <span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <h2 id="parentheses-for-sizeof-arguments">Parentheses for sizeof arguments</h2> <p>When using the sizeof operator in code, we prefer it to be written with parentheses around its argument:</p> <div class="sourceCode" id="cb15"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> size <span class="op">=</span> <span class="kw">sizeof</span><span class="op">(</span><span class="dt">int</span><span class="op">);</span></span></code></pre></div> <h2 id="column-alignment">Column alignment</h2> <p>Some statements cannot be completed on a single line because the line would be too long, the statement too hard to read, or due to other style guidelines above. In such a case the statement spans multiple lines.</p> <p>If a continuation line is part of an expression or sub-expression then you should align on the appropriate column so that it is easy to tell what part of the statement it is. Operators should not start continuation lines. In other cases follow the 2-space indent guideline. Here are some examples from libcurl:</p> <div class="sourceCode" id="cb16"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>Curl_pipeline_wanted<span class="op">(</span>handle<span class="op">-></span>multi<span class="op">,</span> CURLPIPE_HTTP1<span class="op">)</span> <span class="op">&&</span></span> <span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>handle<span class="op">-></span>set<span class="op">.</span>httpversion <span class="op">!=</span> CURL_HTTP_VERSION_1_0<span class="op">)</span> <span class="op">&&</span></span> <span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>handle<span class="op">-></span>set<span class="op">.</span>httpreq <span class="op">==</span> HTTPREQ_GET <span class="op">||</span></span> <span id="cb16-4"><a href="#cb16-4" aria-hidden="true" tabindex="-1"></a> handle<span class="op">-></span>set<span class="op">.</span>httpreq <span class="op">==</span> HTTPREQ_HEAD<span class="op">))</span></span> <span id="cb16-5"><a href="#cb16-5" aria-hidden="true" tabindex="-1"></a> <span class="co">/* did not ask for HTTP/1.0 and a GET or HEAD */</span></span> <span id="cb16-6"><a href="#cb16-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> TRUE<span class="op">;</span></span></code></pre></div> <p>If no parenthesis, use the default indent:</p> <div class="sourceCode" id="cb17"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>data<span class="op">-></span>set<span class="op">.</span>http_disable_hostname_check_before_authentication <span class="op">=</span></span> <span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span><span class="dv">0</span> <span class="op">!=</span> va_arg<span class="op">(</span>param<span class="op">,</span> <span class="dt">long</span><span class="op">))</span> <span class="op">?</span> TRUE <span class="op">:</span> FALSE<span class="op">;</span></span></code></pre></div> <p>Function invoke with an open parenthesis:</p> <div class="sourceCode" id="cb18"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span><span class="op">(</span>option<span class="op">)</span> <span class="op">{</span></span> <span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a> result <span class="op">=</span> parse_login_details<span class="op">(</span>option<span class="op">,</span> strlen<span class="op">(</span>option<span class="op">),</span></span> <span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>userp <span class="op">?</span> <span class="op">&</span>user <span class="op">:</span> NULL<span class="op">),</span></span> <span id="cb18-4"><a href="#cb18-4" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span>passwdp <span class="op">?</span> <span class="op">&</span>passwd <span class="op">:</span> NULL<span class="op">),</span></span> <span id="cb18-5"><a href="#cb18-5" aria-hidden="true" tabindex="-1"></a> NULL<span class="op">);</span></span> <span id="cb18-6"><a href="#cb18-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code></pre></div> <p>Align with the "current open" parenthesis:</p> <div class="sourceCode" id="cb19"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a>DEBUGF<span class="op">(</span>infof<span class="op">(</span>data<span class="op">,</span> <span class="st">"Curl_pp_readresp_ %d bytes of trailing "</span></span> <span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a> <span class="st">"server response left</span><span class="sc">\n</span><span class="st">"</span><span class="op">,</span></span> <span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a> <span class="op">(</span><span class="dt">int</span><span class="op">)</span>clipamount<span class="op">));</span></span></code></pre></div> <h2 id="platform-dependent-code">Platform dependent code</h2> <p>Use <strong>#ifdef HAVE_FEATURE</strong> to do conditional code. We avoid checking for particular operating systems or hardware in the #ifdef lines. The HAVE_FEATURE shall be generated by the configure script for Unix-like systems and they are hard-coded in the <code>config-[system].h</code> files for the others.</p> <p>We also encourage use of macros/functions that possibly are empty or defined to constants when libcurl is built without that feature, to make the code seamless. Like this example where the <strong>magic()</strong> function works differently depending on a build-time conditional:</p> <div class="sourceCode" id="cb20"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="pp">#ifdef HAVE_MAGIC</span></span> <span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a><span class="dt">void</span> magic<span class="op">(</span><span class="dt">int</span> a<span class="op">)</span></span> <span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a><span class="op">{</span></span> <span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> a <span class="op">+</span> <span class="dv">2</span><span class="op">;</span></span> <span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span> <span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a><span class="pp">#else</span></span> <span id="cb20-7"><a href="#cb20-7" aria-hidden="true" tabindex="-1"></a><span class="pp">#define magic(x) 1</span></span> <span id="cb20-8"><a href="#cb20-8" aria-hidden="true" tabindex="-1"></a><span class="pp">#endif</span></span> <span id="cb20-9"><a href="#cb20-9" aria-hidden="true" tabindex="-1"></a></span> <span id="cb20-10"><a href="#cb20-10" aria-hidden="true" tabindex="-1"></a><span class="dt">int</span> content <span class="op">=</span> magic<span class="op">(</span><span class="dv">3</span><span class="op">);</span></span></code></pre></div> <h2 id="no-typedefed-structs">No typedefed structs</h2> <p>Use structs by all means, but do not typedef them. Use the <code>struct name</code> way of identifying them:</p> <div class="sourceCode" id="cb21"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a><span class="kw">struct</span> something <span class="op">{</span></span> <span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">void</span> <span class="op">*</span>valid<span class="op">;</span></span> <span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">size_t</span> way_to_write<span class="op">;</span></span> <span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a><span class="op">};</span></span> <span id="cb21-5"><a href="#cb21-5" aria-hidden="true" tabindex="-1"></a><span class="kw">struct</span> something instance<span class="op">;</span></span></code></pre></div> <p><strong>Not okay</strong>:</p> <div class="sourceCode" id="cb22"><pre class="sourceCode c"><code class="sourceCode c"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a><span class="kw">typedef</span> <span class="kw">struct</span> <span class="op">{</span></span> <span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">void</span> <span class="op">*</span>wrong<span class="op">;</span></span> <span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">size_t</span> way_to_write<span class="op">;</span></span> <span id="cb22-4"><a href="#cb22-4" aria-hidden="true" tabindex="-1"></a><span class="op">}</span> something<span class="op">;</span></span> <span id="cb22-5"><a href="#cb22-5" aria-hidden="true" tabindex="-1"></a>something instance<span class="op">;</span></span></code></pre></div> </div> </div> </body> </html>