Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changes between Version 2 and Version 3 of CStyle


Ignore:
Timestamp:
2013-05-23T12:14:22Z (9 years ago)
Author:
Jiri Svoboda
Comment:

Elaborate and extend

Legend:

Unmodified
Added
Removed
Modified
  • CStyle

    v2 v3  
    1 == HelenOS Coding Style Standard ==
     1== HelenOS C Coding Style Standard ==
    22
    3 === Entity Naming ===
     3Any source contribution to HelenOS must follow the C style rules described below.
    44
    5  * Names' words shall be separated by underscore "_".
    6  * Types shall be suffixed with "_t".
    7  * Macros shall be upper case.
     5=== Source file encoding ===
     6
     7 * Source files are encoded in UTF-8
     8 * Only ASCII subset should be used, except for cases of internationalized string literals
     9 * New lines are represented by the LF ('\n') character. Do not use CR + LF or CR.
     10
     11=== Identifiers ===
     12
     13 * C identifiers should be written in lower case, words separated by underscore "_" (foo_bar)
     14 * Types shall be suffixed with "_t"
     15 * Preprocesor symbols shall be all-upper case (FOO_MACRO(), FOO_CONSTANT)
    816
    917=== Names ===
    1018
    1119 * Use sensible, descriptive names.
    12  * Only use English names.
    13  * Variables with a large scope should have long names, variables with a small scope can have short names.
    14  * Use name prefixes for identifiers declared in different modules.
     20 * Only use English names (English words, intelligible abbreviations)
     21 * Symbols with narrow scope (local variables) may have terse names (e.g. i)
     22 * Symbols with wide scope must have reasonably unique and meaningful names
     23 * Symbols with module scope or wider scope should follow the prefixing convention (e.g. fibril_create)
    1524
    16 === Indentation and Spacing ===
     25=== Indentation ===
    1726
    18  * Do not use spaces for indentation, except for long line wrapping purposes.
    19  * Consider breaking long lines at 80-character boundary. The wrapped line should continue indented four spaces to the right of the original indentation.
     27 * Use a single Tab character for indentation, except for line continuations.
     28 * Tab width is considered to be 8 characters.
     29 * A line continuation is indented exactly 4 spaces.
     30 * Lines should not, in general, exceed 80 characters (tab counting as 8).
    2031 * Each statement shall be placed on a line on its own.
    2132 * Braces shall follow [http://en.wikipedia.org/wiki/Indent_style#K.26R_style K&R Bracing Style]
    22    * I.e. for functions the opening braces starts at a new line
     33   * For functions the opening brace should be at a new line
     34   * In all other cases the opening brace should be at the same line as the previous token
    2335 * Blocks within braces shall be indented 1 tab to the right as compared to the enclosing braces
    2436 * Braces without any contents may be placed on the same line.
    25  * Blocks containing a single statement can omit braces
     37 * Blocks containing a single line can omit braces
    2638   * For if...else statements both or neither of the T, F blocks must be delimited by braces
    27  * All binary arithmetic, bitwise and assignment operators and the ternary conditional operator (?:) shall be surrounded by spaces; the comma operator shall be followed by a space but not preceded; all other operators shall not be used with spaces.
     39 * Labels in functions and switch statements are not indented (i.e. indented one less tab than the other contents of the block)
     40
     41=== Spacing ===
     42
     43 * All binary arithmetic, bitwise and assignment operators and the ternary conditional operator (?:) shall be surrounded by spaces
     44 * The comma operator shall be followed by a space but not preceded
     45 * All other operators shall not be used with spaces.
     46 * For functions and function-like operators there should be no extra spaces around or inside parentheses (int foo(void), sizeof(bar_t))
     47 * For control statements with parenteses there should be one space between the keyword and opening parenthesis (if (a == b))
     48 * Return statements should omit parentheses, especially when the argument is simple (return 1;)
     49 * Function-like operators (sizeof()) must never omit parentheses
     50 * There should be no space after asterisk (in type declarations or when dereferencing) (int *foo(int *f), *f = *g[3])
     51
     52=== Blank lines ===
     53
     54 * There should be newline at the end of every source file
     55 * There should be one blank line between any two top-level declarations that include a { } body - functions, enums, structs
    2856
    2957=== Comments ===
    3058
    31  * Comments shall be written in English.
     59 * Only /* */ comments are allowed. // comments are prohibited
     60 * Comments shall be written in gramatically correct English.
     61 * Comments describing action should be written in infinitive tense (/* Create a new entry on the stack. */)
     62 * Short comments need not be a complete sentence and need not end in '.' Such sentence fragments usually do not contain articles (/* Close callback connection */)
    3263 * Multiline comments begin with "*" on each inner line.
     64 * The first line of a multiline comment must be just '/*' and the comment itself must start on the next line ('* Comment...')
    3365 * Use Doxygen style comments for documenting functions.
    3466 * All comments shall be placed above the line the comment describes, indented identically.
    35  * Every function shall have a comment that describes its purpose.
     67 * Every source file, function, type shall have a comment that describes its purpose.
     68 * Bazaar commit comments must follow [wiki:BazaarCommitRules very similar rules]
    3669
    3770=== Miscellaneous ===
    3871
    39  * New lines are represented by the LF ('\n') character. Do not use CR + LF or CR.
     72 * Copyright headers must follow the [wiki:CopyrightRules copyright rules]
    4073 * Do *not* use Yoda comparisons (e.g. NULL == ptr)