This commit is contained in:
Nilstrieb 2022-08-02 05:44:38 +00:00
parent 492783020c
commit 9a13559cb2
6 changed files with 9 additions and 9 deletions

View file

@ -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