.. _decisions_file_structure: ============== File Structure ============== Summary ======= Issue ----- Decision -------- Status ------ Details ======= Assumption ---------- * `Clang-Format `__ is used as the formatter based on `Google style `__. Constraints ----------- Positions --------- This record generally follows the `Google C++ Style Guide `__ and `Linux Kernel Coding Style `__, and will refer to them later as "Google Guide" and "Linux Guide" respectively. The structure of source file (.c) should be as follows: 1. ``#include`` directives that follow; * Order of includes from the `Google Guide `__ .. note:: Since Clang-Format will remove blink lines between includes, use comments to separate includes form different categories. * Avoid transitive includes as mentioned in the `Google Guide `__ 2. ``#define`` directives for macros and constants 3. Type fordward declarations only for types that will be defined later in the same file 4. Typedefs 5. Type declarations in the following order; 1. Enums 2. Structs 3. Unions 6. Static function declarations 7. External variables 8. Static variables 9. Function definitions 10. Static function definitions With the exception of conditional compilation, which should be grouped together for readability, refer to the `Linux Guide `__ to write code with conditional compilation better. Within a module, group global variables into a single context struct :c:struct:`MODULE_NAME_ctx`. Initialize its member in a static initializer if possible and define a :c:func:`MODULE_NAME_init` function to initialize other members unable to be initialized in the static initializer. Arguments --------- Implications ------------ Notes ===== * `Google C++ Style Guide `__ * `Zephyr Coding Style Guidelines `__ * `Linux Kernel Coding Style `__