summaryrefslogtreecommitdiffstatshomepage
path: root/CODECONVENTIONS.md
blob: a0e0fc7ab234bca8209ea87aad2b3b459c581431 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Code conventions
================

When writing new code, please adhere to the following conventions.

White space:
- Expand tabs to 4 spaces.
- Don't leave trailing whitespace at the end of a line.
- For control blocks (if, for, while), put 1 space between the
  keyword and the opening parenthesis.
- Put 1 space after a comma, and 1 space around operators.

Braces: 
- Use braces for all blocks, even no-line and single-line pieces of
  code.
- Put opening braces on the end of the line it belongs to, not on
  a new line.
- For else-statements, put the else on the same line as the previous
  closing brace.

Include directives:
- Don't include within a header file.

Type names and declarations:
- When defining a type, put '_t' after it.

Examples
--------

Braces and spaces:

    int foo(int x, int y) {
        if (x < y) {
            foo(y, x);
        } else {
            foo(x + 1, y - 1);
        }

        for (int i = 0; i < x; i++) {
        }
    }

Type declarations:

    typedef struct _my_struct_t {
        int member;
        void *data;
    } my_struct_t;