Skip to content
Snippets Groups Projects
CodingStyle.txt 1.24 KiB
Newer Older
$Id$

vim: spelllang=en tw=78

This is a short introduction to the coding style that shall be used. The below
rules are applicable for all C source files, except the Ethernet drivers, for
which the Linux Kernel coding style shall be used to minimize the
differences).

Florian Pose's avatar
Florian Pose committed
1) Line length
Florian Pose's avatar
Florian Pose committed
- Lines shall not exceed 78 characters.
Florian Pose's avatar
Florian Pose committed
2) Whitespace
Florian Pose's avatar
Florian Pose committed
- Indentation shall be done using 4 space characters
Florian Pose's avatar
Florian Pose committed
- No whitespace shall be left at the end of a line.

- After commas, colons and semicolons, a single space shall be
  placed (if not followed by a line break).

- Binary operators (=, ==, ~=, |, ||, etc.) shall be enclosed by 2 spaces
  (except . and ->).

3) Placing braces

- Braces shall be placed in the following way (K&R style):

    if (...) {
        ...
    } else if (...) {
        ...
    } else {
        ...
    }

    int function(...)
    {
        ...
    }

Florian Pose's avatar
Florian Pose committed
4) Defines and Macros

- Defines and macros shall be named in CAPITAL letters. If a macro contains
  multiple statements, they should be enclosed by a 'do {} while (0)' loop.
  Macro parameters shall also be capital letters and shall be enclosed py
  parantheses if necessary.

    #define MACRO(A, B) \
        do { \
            if ((A) == 1) { \
                statement(B); \
        } while (0)