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* Use `snake case`_ for code and variables.
20* The line length is 100 columns or fewer. In the documentation, longer lines
21  for URL references are an allowed exception.
22* Add braces to every ``if``, ``else``, ``do``, ``while``, ``for`` and
23  ``switch`` body, even for single-line code blocks.
24* Use spaces instead of tabs to align comments after declarations, as needed.
25* Use C89-style single line comments, ``/*  */``. The C99-style single line
26  comment, ``//``, is not allowed.
27* Use ``/**  */`` for doxygen comments that need to appear in the documentation.
28* Avoid using binary literals (constants starting with ``0b``).
29* Avoid using non-ASCII symbols in code, unless it significantly improves
30  clarity, avoid emojis in any case.
31* Use proper capitalization of nouns in code comments (e.g. ``UART`` and not
32  ``uart``, ``CMake`` and not ``cmake``).
33
34.. _Linux kernel coding style:
35   https://kernel.org/doc/html/latest/process/coding-style.html
36
37.. _snake case:
38   https://en.wikipedia.org/wiki/Snake_case
39