mirror of
https://github.com/Noratrieb/nilstrieb-c-style-guide-edition-2.git
synced 2026-01-14 15:25:10 +01:00
deploy: 23a4876ff9
This commit is contained in:
parent
52edb5c934
commit
f95c82ece5
4 changed files with 4 additions and 4 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, derefence 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 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>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>
|
||||
|
|
|
|||
|
|
@ -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, derefence 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 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>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>
|
||||
|
|
|
|||
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