blob: 7d351c393e0de007f9e3ca22b21783d2c4870ce8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
This page describes the X server's current coding style. While the server was recently reformatted to fit this style, most modules have varied and disparate coding styles. Above all, the cardinal rule is to fit in: make sure your changes reflect the coding style of the surrounding code.
We use the `indent` command line in this script here: [[http://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh|http://cgit.freedesktop.org/xorg/util/modular/tree/x-indent.sh]] with manual editing afterwards to fix the cases where indent gets hopelessly confused.
* Four-space indents (no tabs, not even if your editor wants to collapse eight consecutive spaces down to a single tab)
* 78-column limit
* Function return type (and any modifiers, eg `static`) on a line by itself
* Opening curly brace on the same line as the control construct: `if (foo) {`
* Closing braces aligned with the keyword that opened them (K&R not GNU)
* `else` on a new line from the closing } of the preceding `if` (i.e. not cuddling)
* Opening curly brace for functions in column 0
* Keywords punctuated like `if (x >= 0)`
* Functions punctuated like `doSomethingClever(a, b, c);`
* `case` aligned in the same column as the `switch`
* If wrapping is required, function arguments to be aligned to the opening parenthesis of that column
* Wrap structs in typedefs
* C-style <span style="display:none">foo</span> comments, rather than C++/C99-style // foo
* C89 + some extensions, see [[http://cgit.freedesktop.org/xorg/xserver/tree/doc/c-extensions|http://cgit.freedesktop.org/xorg/xserver/tree/doc/c-extensions]]
Notable objectionable things in the current coding style:
* Most structs have a typedef both for the struct and for a pointer to the struct.
|