mirror of
https://github.com/Noratrieb/nilstrieb-c-style-guide-edition-2.git
synced 2026-01-16 16:25:09 +01:00
style
This commit is contained in:
parent
296254f132
commit
bda9cace24
3 changed files with 51 additions and 1 deletions
|
|
@ -1 +1,36 @@
|
|||
# Formatting
|
||||
# Formatting
|
||||
|
||||
The Nilstrieb C Style Guide Edition 2 mostly follows the principle of maximal readability.
|
||||
Code, especially C code, is mostly read (by security researchers to find the vulnerabilities),
|
||||
and therefore readability comes before writability.
|
||||
|
||||
## Control flow
|
||||
|
||||
Never use braces with `if`/`while`/`do`/`for` statements as they introduce clutter. If your
|
||||
body cannot fit into a single line, make a new function instead.
|
||||
|
||||
```c
|
||||
#include<stdio.h>
|
||||
|
||||
void foo_if_body() {
|
||||
printf("Hello, ");
|
||||
printf("World!");
|
||||
}
|
||||
|
||||
void foo() {
|
||||
if (true)
|
||||
foo_if_body();
|
||||
else
|
||||
printf("True was false!");
|
||||
}
|
||||
```
|
||||
|
||||
## Identation
|
||||
|
||||
C code must be indented with 3 spaces. The toplevel should be indented as well.
|
||||
|
||||
```c
|
||||
#include<stdio.h>
|
||||
|
||||
int main() {}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue