From 144b1236f43ccb126415a1a2d518675c00f9f778 Mon Sep 17 00:00:00 2001 From: pacien Date: Tue, 28 Nov 2017 20:18:57 +0100 Subject: Add code style guidelines Signed-off-by: pacien --- doc/topics/code-style.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 doc/topics/code-style.txt (limited to 'doc/topics') 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 @@ +Title: Code style + + +About: Source formatting + +- C sources must be properly indented using two spaces per nesting level. +- Opening braces are put on the same line as there prelude statement and may be omitted consistently per block. +- Booleans from `stdbool` are preferred to binary integer values. +- Inside comparisons, the constant part should be on the right. +- Pointer declaration must be put adjacent to the declared identifier, not to the type. + +In brief, a function should look like so: + +> char *f(char *c) { +> if (c % 2 == 0) +> return 1; +> else if (c == 1) +> return 2; +> else +> return 3; +> } + + +About: Code structure + +- Variables are declared at the top of a context. +- It is advised to declare variables on the stack instead of the heap when possible. +- The use of `assert` is encouraged. +- The use of `static` functions is encouraged. Such members must be declared prior to others. + + +About: Unit tests + +- Unit test files have the `.test.c` extension. -- cgit v1.2.3