forked from clearlinux/telemetrics-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CODING-STYLE
78 lines (56 loc) · 2.29 KB
/
CODING-STYLE
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
Indentation
-----------
telemetrics-client uses spaces for indentation (no tabs). To help enforce this
rule, all source files provide modelines; if your editor does not support
modelines, configure your editor accordingly.
Line length
-----------
Wherever possible, try to limit line length to 80 characters.
Coding Style
------------
- Function declarations and invocations should include no space between the
function name and the open parenthesis:
spool_max_size_config();
- All other usages of parentheses in code should have one intervening space:
if (spool_size == -1) {
...
}
- To distinguish function definitions from other top-level constructs, add the
opening curly bracket on its own line:
void spool_record(char *headers[], char *body)
{
...
}
- All other usages of curly brackets in code should include the opening curly
bracket at the end of the line which opens the block:
for (i = 0; i < NUM_HEADERS; i++) {
...
}
- if statements should *always* use curly brackets, even when each clause only
contains a single statement. This is a safeguard to ensure future changes to
an if statement are not buggy due to forgetting to add the curly brackets
when needed.
if (ret == -1) {
...
}
- Comments that span more than one line should use the following style:
/* This comment
* spans more
* than one
* line.
*/
- For single-line comments, use either of the following forms:
/* single line comment 1 */
// single line comment 2
- To make type casts stand out more, include no space between the cast and the
variable, etc. to cast:
nc_string **foo = (nc_string **)bar;
- Whenever arithmetic operators are used, always include one space before and
after each operator:
size = size - offset + 1;
- For pointer variable declarations, pointer dereferences, functions that return
a pointer, typecasts to a pointer variable, and other related constructs;
include a single space between the type and '*', and no space between the '*'
and the following variable, function name, etc. The purpose here is to
distinguish pointer usage versus arithmetic usage:
char *payload;