summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
Diffstat (limited to 'doc')
-rw-r--r--doc/topics/code-style.txt34
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/topics/code-style.txt b/doc/topics/code-style.txt
new file mode 100644
index 0000000..45318ab
--- /dev/null
+++ b/doc/topics/code-style.txt
@@ -0,0 +1,34 @@
1Title: Code style
2
3
4About: Source formatting
5
6- C sources must be properly indented using two spaces per nesting level.
7- Opening braces are put on the same line as there prelude statement and may be omitted consistently per block.
8- Booleans from `stdbool` are preferred to binary integer values.
9- Inside comparisons, the constant part should be on the right.
10- Pointer declaration must be put adjacent to the declared identifier, not to the type.
11
12In brief, a function should look like so:
13
14> char *f(char *c) {
15> if (c % 2 == 0)
16> return 1;
17> else if (c == 1)
18> return 2;
19> else
20> return 3;
21> }
22
23
24About: Code structure
25
26- Variables are declared at the top of a context.
27- It is advised to declare variables on the stack instead of the heap when possible.
28- The use of `assert` is encouraged.
29- The use of `static` functions is encouraged. Such members must be declared prior to others.
30
31
32About: Unit tests
33
34- Unit test files have the `.test.c` extension.