~sircmpwn/ctools

ref: cc69324393fda9bcbc73d30d1bda022263f012a8 ctools/STYLE -rw-r--r-- 1.4 KiB View raw
cc693243 — Gabor Koszegi Correct tee SIGINT test 4 months ago
                                                                                
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
ctools is written in a style which approximates Linux kernel style.

Opening braces go on the same line, except for function definitions, and are
mandatory in cases where C99 permits their omission (e.g. one-line if
statements).

	if (cond) {
		...
	}

	while (cond) {
		...
	}

Functions are defined as such:

	return type
	name(parameters...)
	{
		body
	}

This enables them to be easily found with `grep -Rn '^name' .`

Pointer types are defined with the * placed with the identifier:

	char *foobar;

Spaces are placed around binary operators, but not unary:

	int x = y * (2 + z);
	do_work(x, +y, -z);

The use of macros is not permitted.

Comments should use /* multi-line style */ even for single-line comments.

#include statements at the top of the file are to organized by locality (<>
first, then ""), then alphabetized.

The line length limit is 80 columns. Tabs are 8 columns wide. Identation with
spaces is not used.

When breaking a statement onto several lines, indent the subsequent lines once.
If the statement declares a block, indent twice instead;

	int x = 100,
		y = 200,
		z = 300;

	if (x == 100 && y == 200
			&& z == 300) {
		do_work(x, y, z);
	}

Hexadecimal literals should be written in uppercase: 0xDEADBEEF.

Align case statements with the switch statement they belong to:

	switch (x) {
	case 10:
		do_work(x);
		break;
	case 20:
		do_work(x);
		break;
	}