2125
|
1 |
$Id$
|
|
2 |
|
|
3 |
vim: spelllang=en tw=78
|
|
4 |
|
|
5 |
This is a short introduction to the coding style that shall be used. The below
|
|
6 |
rules are applicable for all C source files, except the Ethernet drivers, for
|
|
7 |
which the Linux Kernel coding style shall be used to minimize the
|
|
8 |
differences).
|
|
9 |
|
2128
|
10 |
1) Line length
|
2125
|
11 |
|
2128
|
12 |
- Lines shall not exceed 78 characters.
|
2125
|
13 |
|
2128
|
14 |
2) Whitespace
|
2125
|
15 |
|
2128
|
16 |
- Indentation shall be done using 4 space characters
|
2125
|
17 |
|
2128
|
18 |
- No whitespace shall be left at the end of a line.
|
|
19 |
|
|
20 |
- After commas, colons and semicolons, a single space shall be
|
|
21 |
placed (if not followed by a line break).
|
|
22 |
|
|
23 |
- Binary operators (=, ==, ~=, |, ||, etc.) shall be enclosed by 2 spaces
|
|
24 |
(except . and ->).
|
|
25 |
|
|
26 |
3) Placing braces
|
|
27 |
|
|
28 |
- Braces shall be placed in the following way (K&R style):
|
2125
|
29 |
|
|
30 |
if (...) {
|
|
31 |
...
|
|
32 |
} else if (...) {
|
|
33 |
...
|
|
34 |
} else {
|
|
35 |
...
|
|
36 |
}
|
|
37 |
|
|
38 |
int function(...)
|
|
39 |
{
|
|
40 |
...
|
|
41 |
}
|
|
42 |
|
2128
|
43 |
4) Defines and Macros
|
|
44 |
|
|
45 |
- Defines and macros shall be named in CAPITAL letters. If a macro contains
|
|
46 |
multiple statements, they should be enclosed by a 'do {} while (0)' loop.
|
|
47 |
Macro parameters shall also be capital letters and shall be enclosed py
|
|
48 |
parantheses if necessary.
|
2125
|
49 |
|
|
50 |
#define MACRO(A, B) \
|
|
51 |
do { \
|
|
52 |
if ((A) == 1) { \
|
|
53 |
statement(B); \
|
|
54 |
} while (0)
|
|
55 |
|