diff options
-rw-r--r-- | doc/topics/code-style.txt | 34 | ||||
-rw-r--r-- | makefile | 2 |
2 files changed, 35 insertions, 1 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 @@ | |||
1 | Title: Code style | ||
2 | |||
3 | |||
4 | About: 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 | |||
12 | In 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 | |||
24 | About: 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 | |||
32 | About: Unit tests | ||
33 | |||
34 | - Unit test files have the `.test.c` extension. | ||
@@ -1,6 +1,6 @@ | |||
1 | api-doc: | 1 | api-doc: |
2 | $(eval TMPDIR := $(shell mktemp -d)) | 2 | $(eval TMPDIR := $(shell mktemp -d)) |
3 | naturaldocs --project $(TMPDIR) --input include/ --output HTML doc/api/ | 3 | naturaldocs --project $(TMPDIR) --input include/ --input doc/topics/ --output HTML doc/api/ |
4 | $(RM) -r $(TMPDIR) | 4 | $(RM) -r $(TMPDIR) |
5 | 5 | ||
6 | report: | 6 | report: |