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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
Waffle's coding style is heavily influenced by the Linux kernel and XCB.
When in doubt, follow the style of nearby code.
Naming
======
All symbols exposed in the public API must be prefixed with `waffle_` or
`WAFFLE_`.
No camelCase, itIsSoHardToRead, especiallyWhenTheVariableNameContainsAnUpperCaseAcronym.
Function and variable names are lower_case_with_underscores.
Enum and macro names are UPPER_CASE_WITH_UNDERSCORES.
Comments
========
Non-Doxygen comments begin with '//'. Do not use '/*'-style comments.
There are special exceptions, such as when commenting items in a table. Use
your judgement.
Doxygen comments begin with '///' or '//!'.
Indentation
===========
Indent 4 spaces. No tabs.
Place a function's return type on its own line. This ensures that all function
names are aligned and makes it easier to quickly find a function when scanning
the source.
void
make_coffee(int x, int y);
If a function prototype has a longwinded parameter list, then indent it like this:
void
make_fancy_coffee(
struct coffee_mug *mug,
struct french_press *press,
struct sugar_dish *sugar);
or this:
void
make_fancy_coffee(struct coffee_mug *mug,
struct french_press *press,
struct sugar_dish *sugar);
Indent cases in switch statements. The last case always requires a jump
(break, return, goto).
switch (time) {
case 600:
case 1545:
wake_up();
break;
case 1500:
case 2200:
sleep();
break;
default:
breathe();
break;
}
Don't put multiple statements on a single line.
BAD:
if (condition) do_something;
GOOD:
if (condition) {
do_something;
}
Spaces
======
Leave no trailing whitespace on end of lines. This can cause spurious commit
conflicts.
A single empty line separates function and struct defintions.
Do not add spaces inside a parenthesized expression.
bad: foo( x, y );
Place a space after these keywords:
if, switch, case, for, do, while
For keywords that are typically used as functions, do not follow the keyword
with a space and do enclose the arguments with parentheses. The keywords are:
sizeof, typeof, alignof, __attribute__
When declaring a variable or argument with pointer type, the '*' goes adjacent
to the variable or argument name.
void
make_fancy_coffee(
struct coffee_mug *mug,
struct french_press *press,
struct sugar_dish *sugar)
{
void *mystery_ingredient = mug + press + sugar;
...
}
No spaces around unary operators.
--y;
!z;
No spaces around the structure member operators: '.' and '->'.
cow->tail
teapot.spout
Place a single space before and after the binary operators.
a + b
x == y
|