1.. _general_code_style:
2
3C Code and General Style Guidelines
4###################################
5
6Coding style is enforced on any new or modified code, but contributors are
7not expected to correct the style on existing code that they are not
8modifying.
9
10For style aspects where the guidelines don't offer explicit guidance or
11permit multiple valid ways to express something, contributors should follow
12the style of existing code in the tree, with higher importance given to
13"nearby" code (first look at the function, then the same file, then
14subsystem, etc).
15
16In general, follow the `Linux kernel coding style`_, with the following
17exceptions and clarifications:
18
19* Tabs are 8 characters.
20* Use `snake case`_ for code and variables.
21* The line length is 100 columns or fewer. In the documentation, longer lines
22  for URL references are an allowed exception.
23* Add braces to every ``if``, ``else``, ``do``, ``while``, ``for`` and
24  ``switch`` body, even for single-line code blocks.
25* Use spaces instead of tabs to align comments after declarations, as needed.
26* Use C89-style single line comments, ``/*  */``. The C99-style single line
27  comment, ``//``, is not allowed.
28* Use ``/**  */`` for doxygen comments that need to appear in the documentation.
29* Avoid using binary literals (constants starting with ``0b``).
30* Avoid using non-ASCII symbols in code, unless it significantly improves
31  clarity, avoid emojis in any case.
32* Use proper capitalization of nouns in code comments (e.g. ``UART`` and not
33  ``uart``, ``CMake`` and not ``cmake``).
34
35.. _Linux kernel coding style:
36   https://kernel.org/doc/html/latest/process/coding-style.html
37
38.. _snake case:
39   https://en.wikipedia.org/wiki/Snake_case
40