mirror of
https://github.com/Noratrieb/nilstrieb-c-style-guide-edition-2.git
synced 2026-01-14 15:25:10 +01:00
deploy: acf99e34fd
This commit is contained in:
parent
492783020c
commit
9a13559cb2
6 changed files with 9 additions and 9 deletions
|
|
@ -146,7 +146,7 @@
|
|||
<h1 id="conventions"><a class="header" href="#conventions">Conventions</a></h1>
|
||||
<p>General conventions that C code should obey.</p>
|
||||
<h2 id="memory-allocation"><a class="header" href="#memory-allocation">Memory allocation</a></h2>
|
||||
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
|
||||
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonably recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
|
||||
<p>If the pointer is non-null, <code>free</code> it directly after the <code>malloc</code> call. This prevents memory leaks of all sorts. Afterwards,
|
||||
you can use it freely in your program.</p>
|
||||
<h2 id="includes"><a class="header" href="#includes">Includes</a></h2>
|
||||
|
|
@ -154,7 +154,7 @@ you can use it freely in your program.</p>
|
|||
<h2 id="identifers"><a class="header" href="#identifers">Identifers</a></h2>
|
||||
<p>All identifiers should be given meaningful english names. To work with ancient linkers, function names should contain six characters at most.</p>
|
||||
<h2 id="comments"><a class="header" href="#comments">Comments</a></h2>
|
||||
<p>Comments are vital to readability. Therefore, code should always be well commented. Comments must be written in the lingua franca of programming, swiss german.</p>
|
||||
<p>Comments are vital to readability. Therefore, code should always be well commented. Comments must be written in the lingua franca of programming, Swiss German.</p>
|
||||
<pre><code class="language-c">int main() {
|
||||
int five = 5; // füüf
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ body cannot fit into a single line, make a new function instead.</p>
|
|||
}
|
||||
</code></pre>
|
||||
<h2 id="identation"><a class="header" href="#identation">Identation</a></h2>
|
||||
<p>C code must be indented with 3 spaces. The toplevel should be indented as well.</p>
|
||||
<p>C code must be indented with 3 spaces. The top-level should be indented as well.</p>
|
||||
<pre><code class="language-c"> #include<stdio.h>
|
||||
|
||||
int main() {}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ body cannot fit into a single line, make a new function instead.</p>
|
|||
}
|
||||
</code></pre>
|
||||
<h2 id="identation"><a class="header" href="#identation">Identation</a></h2>
|
||||
<p>C code must be indented with 3 spaces. The toplevel should be indented as well.</p>
|
||||
<p>C code must be indented with 3 spaces. The top-level should be indented as well.</p>
|
||||
<pre><code class="language-c"> #include<stdio.h>
|
||||
|
||||
int main() {}
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ body cannot fit into a single line, make a new function instead.</p>
|
|||
}
|
||||
</code></pre>
|
||||
<h2 id="identation"><a class="header" href="#identation">Identation</a></h2>
|
||||
<p>C code must be indented with 3 spaces. The toplevel should be indented as well.</p>
|
||||
<p>C code must be indented with 3 spaces. The top-level should be indented as well.</p>
|
||||
<pre><code class="language-c"> #include<stdio.h>
|
||||
|
||||
int main() {}
|
||||
|
|
@ -174,7 +174,7 @@ body cannot fit into a single line, make a new function instead.</p>
|
|||
<div style="break-before: page; page-break-before: always;"></div><h1 id="conventions"><a class="header" href="#conventions">Conventions</a></h1>
|
||||
<p>General conventions that C code should obey.</p>
|
||||
<h2 id="memory-allocation"><a class="header" href="#memory-allocation">Memory allocation</a></h2>
|
||||
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonable recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
|
||||
<p>Always check the return value of <code>malloc</code>. If it is a null pointer, dereference it to immediately abort the processas as we cannot reasonably recover from OOM in most cases. If such a recovery is possible, recover instead. On some platforms, dereferencing a null pointer does <em>not</em> abort the process. In these cases, the null pointer is a perfectly fine pointer, and just continue using it instead. Note that this derefence should usually be a volatile operation as the compiler would optimize it away otherwise. I have reported upstream issues on compilers about this, but they have not yet answered.</p>
|
||||
<p>If the pointer is non-null, <code>free</code> it directly after the <code>malloc</code> call. This prevents memory leaks of all sorts. Afterwards,
|
||||
you can use it freely in your program.</p>
|
||||
<h2 id="includes"><a class="header" href="#includes">Includes</a></h2>
|
||||
|
|
@ -182,7 +182,7 @@ you can use it freely in your program.</p>
|
|||
<h2 id="identifers"><a class="header" href="#identifers">Identifers</a></h2>
|
||||
<p>All identifiers should be given meaningful english names. To work with ancient linkers, function names should contain six characters at most.</p>
|
||||
<h2 id="comments"><a class="header" href="#comments">Comments</a></h2>
|
||||
<p>Comments are vital to readability. Therefore, code should always be well commented. Comments must be written in the lingua franca of programming, swiss german.</p>
|
||||
<p>Comments are vital to readability. Therefore, code should always be well commented. Comments must be written in the lingua franca of programming, Swiss German.</p>
|
||||
<pre><code class="language-c">int main() {
|
||||
int five = 5; // füüf
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue