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 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 comments, rather than C++/C99-style // foo
C89 + some extensions, see 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.