CodingStyle.txt
branchredundancy
changeset 2294 234ba1162c1c
parent 2293 21b876f552a2
equal deleted inserted replaced
2293:21b876f552a2 2294:234ba1162c1c
     5 This is a short introduction to the coding style that shall be used. The below
     5 This is a short introduction to the coding style that shall be used. The below
     6 rules are applicable for all C source files, except the Ethernet drivers, for
     6 rules are applicable for all C source files, except the Ethernet drivers, for
     7 which the Linux Kernel coding style shall be used to minimize the
     7 which the Linux Kernel coding style shall be used to minimize the
     8 differences).
     8 differences).
     9 
     9 
    10 * Lines shall not exceed 78 characters.
    10 1) Line length
    11 
    11 
    12 * Indentation shall be done using 4 space characters
    12 - Lines shall not exceed 78 characters.
    13 
    13 
    14 * No whitespace shall be left at the end of a line.
    14 2) Whitespace
    15 
    15 
    16 * After a comma, a single space shall be placed (if not followed by a
    16 - Indentation shall be done using 4 space characters
    17   line break).
       
    18 
    17 
    19 * Braces shall be placed in the following way (K&R style):
    18 - No whitespace shall be left at the end of a line.
       
    19 
       
    20 - After commas, colons and semicolons, a single space shall be
       
    21   placed (if not followed by a line break).
       
    22 
       
    23 - Binary operators (=, ==, ~=, |, ||, etc.) shall be enclosed by 2 spaces
       
    24   (except . and ->).
       
    25 
       
    26 3) Placing braces
       
    27 
       
    28 - Braces shall be placed in the following way (K&R style):
    20 
    29 
    21     if (...) {
    30     if (...) {
    22         ...
    31         ...
    23     } else if (...) {
    32     } else if (...) {
    24         ...
    33         ...
    29     int function(...)
    38     int function(...)
    30     {
    39     {
    31         ...
    40         ...
    32     }
    41     }
    33 
    42 
    34 * Macros shall be named in CAPITAL letters. If a macro contains multiple
    43 4) Defines and Macros
    35   statements, they should be enclosed by a 'do {} while (0)' loop. Macro
    44 
    36   parameters shall also be capital letters and shall be enclosed py parantheses
    45 - Defines and macros shall be named in CAPITAL letters. If a macro contains
    37   if necessary.
    46   multiple statements, they should be enclosed by a 'do {} while (0)' loop.
       
    47   Macro parameters shall also be capital letters and shall be enclosed py
       
    48   parantheses if necessary.
    38 
    49 
    39     #define MACRO(A, B) \
    50     #define MACRO(A, B) \
    40         do { \
    51         do { \
    41             if ((A) == 1) { \
    52             if ((A) == 1) { \
    42                 statement(B); \
    53                 statement(B); \