CodingStyle.txt
author Florian Pose <fp@igh-essen.com>
Tue, 04 Dec 2012 12:22:38 +0100
branchstable-1.5
changeset 2458 8e0bab31fddd
parent 2128 e645d0d83b3b
permissions -rw-r--r--
Removed unused method.
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
$Id$
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
vim: spelllang=en tw=78
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
This is a short introduction to the coding style that shall be used. The below
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
rules are applicable for all C source files, except the Ethernet drivers, for
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
which the Linux Kernel coding style shall be used to minimize the
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
differences).
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    10
1) Line length
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    12
- Lines shall not exceed 78 characters.
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    14
2) Whitespace
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    16
- Indentation shall be done using 4 space characters
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    18
- No whitespace shall be left at the end of a line.
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    19
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    20
- After commas, colons and semicolons, a single space shall be
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    21
  placed (if not followed by a line break).
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    22
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    23
- Binary operators (=, ==, ~=, |, ||, etc.) shall be enclosed by 2 spaces
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    24
  (except . and ->).
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    25
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    26
3) Placing braces
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    27
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    28
- Braces shall be placed in the following way (K&R style):
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
    if (...) {
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
        ...
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
    } else if (...) {
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
        ...
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
    } else {
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
        ...
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
    }
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
    int function(...)
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
    {
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
        ...
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
    }
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
2128
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    43
4) Defines and Macros
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    44
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    45
- Defines and macros shall be named in CAPITAL letters. If a macro contains
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    46
  multiple statements, they should be enclosed by a 'do {} while (0)' loop.
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    47
  Macro parameters shall also be capital letters and shall be enclosed py
e645d0d83b3b Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2125
diff changeset
    48
  parantheses if necessary.
2125
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    #define MACRO(A, B) \
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        do { \
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
            if ((A) == 1) { \
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
                statement(B); \
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        } while (0)
af3eda069078 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55