mirror of
https://github.com/Noratrieb/nilstrieb-c-style-guide-edition-2.git
synced 2026-01-14 15:25:10 +01:00
Update conventions.md
This commit is contained in:
parent
c98f09048c
commit
23a4876ff9
1 changed files with 1 additions and 1 deletions
|
|
@ -4,7 +4,7 @@ General conventions that C code should obey.
|
||||||
|
|
||||||
## Memory allocation
|
## Memory allocation
|
||||||
|
|
||||||
Always check the return value of `malloc`. 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 _not_ 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.
|
Always check the return value of `malloc`. 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 _not_ 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.
|
||||||
|
|
||||||
If the pointer is non-null, `free` it directly after the `malloc` call. This prevents memory leaks of all sorts. Afterwards,
|
If the pointer is non-null, `free` it directly after the `malloc` call. This prevents memory leaks of all sorts. Afterwards,
|
||||||
you can use it freely in your program.
|
you can use it freely in your program.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue