CodingStyle.txt
author Florian Pose <fp@igh-essen.com>
Thu, 15 Dec 2011 13:21:32 +0100
branchredundancy
changeset 2314 fd8a6fb53d6b
parent 2294 234ba1162c1c
permissions -rw-r--r--
Added e1000 driver for 2.6.32.
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
$Id$
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
vim: spelllang=en tw=78
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
21b876f552a2 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
21b876f552a2 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
21b876f552a2 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
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
differences).
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    10
1) Line length
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    12
- Lines shall not exceed 78 characters.
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    14
2) Whitespace
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    16
- Indentation shall be done using 4 space characters
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    18
- No whitespace shall be left at the end of a line.
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    19
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    20
- After commas, colons and semicolons, a single space shall be
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    21
  placed (if not followed by a line break).
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    22
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    23
- Binary operators (=, ==, ~=, |, ||, etc.) shall be enclosed by 2 spaces
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    24
  (except . and ->).
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    25
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    26
3) Placing braces
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    27
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    28
- Braces shall be placed in the following way (K&R style):
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
    if (...) {
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
        ...
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
    } else if (...) {
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
        ...
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
    } else {
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
        ...
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
    }
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
    int function(...)
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
    {
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
        ...
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
    }
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
2294
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    43
4) Defines and Macros
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    44
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    45
- Defines and macros shall be named in CAPITAL letters. If a macro contains
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    46
  multiple statements, they should be enclosed by a 'do {} while (0)' loop.
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    47
  Macro parameters shall also be capital letters and shall be enclosed py
234ba1162c1c Again coding style.
Florian Pose <fp@igh-essen.com>
parents: 2293
diff changeset
    48
  parantheses if necessary.
2293
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    #define MACRO(A, B) \
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
        do { \
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
            if ((A) == 1) { \
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
                statement(B); \
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
        } while (0)
21b876f552a2 Added coding style document.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55