forked from ClusterLabs/pacemaker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcoding_guidelines.txt
130 lines (95 loc) · 2.83 KB
/
coding_guidelines.txt
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
123
124
125
126
127
128
129
130
= Pacemaker Coding Guidelines =
== Table of Contents ==
1. Introduction
2. Formatting Guidelines
3. Naming Conventions
4. vim Settings
== Introduction ==
The purpose of this document is to discuss guidelines about how to write
code that will be a part of the Pacemaker project.
== Formatting Guidelines ==
=== Whitespace ===
- Indentation must be 4 spaces, no tabs.
- Do not leave trailing whitespace.
=== Line Length ===
- Lines should be no longer than 80 characters unless limiting line length significantly impacts readability.
=== Pointers ===
- The '*' goes by the variable name, not the type:
```
char *foo;
```
- Use a space before the '*' and after the closing parenthesis in a cast:
```
char *foo = (char *) bar;
```
=== Functions ===
- Put the return type on its own line:
- Place the opening brace for a function on the next line:
```
static int
foo(void)
{
```
- For functions with enough arguments that they must break to the next line, align arguments with the first argument:
```
static int
function_name(int bar, const char *a, const char *b,
const char *c, const char *d)
{
```
- If a function name gets really long, start the arguments on their own line with 8 spaces of indentation:
```
static int
really_really_long_function_name_this_is_getting_silly_now(
int bar, const char *a, const char *b,
const char *c, const char *d)
{
```
=== Control statements (if, else, while, for, switch) ===
- Keyword is followed by one space, then left parenthesis witout space,
condition, right parenthesis, space, opening bracket on the same line.
- "else" and "else if" are on the same line with ending brace and opening
brace, separated by space
```
if (condition1) {
statement1;
} else if (condition2) {
statement2;
} else {
statement3;
}
```
- Cases in switch statement have same indentation as switch. Body of cases
is indented by one level. Opening brace is on the same line as switch.
```
switch (expression)
{
case 0:
command0;
break;
case 1:
command1;
break;
default:
command;
}
```
=== Operators ===
- Operators have spaces from both sides. Do not rely on operator precedence,
use brackets when mixing operators with different priority.
- No space after opening bracked and before closing bracket.
```
x = a + b - (c * d);
```
== Naming Conventions ==
- Public C API calls and type names must begin with an API specific prefix, eg. "crm_", "pe_", "st_", "lrm_".
== vim Settings ==
```vim
" This section contains settings that can be placed in the vimrc file that are
" compatible with the Pacemaker coding guidelines.
" Whitespace
set ts=4
set sw=4
set expandtab
let c_space_error=1
```