@@ -107,6 +107,38 @@ void f(bool reverse) {
107107}
108108```
109109
110+ ### Preprocessor Indentation
111+
112+ Indent nested preprocessor directives after the hash mark [ AVMCCS-F022] :
113+ - The hash ` # ` stays in column 1, directives are indented with 4 spaces after the hash
114+ - Each nesting level adds 4 spaces after the ` # `
115+ - ** Exception** : Include guards do not count for indentation. The guard directives themselves
116+ (` #ifndef ` , ` #define ` , ` #endif ` ) and all content between them remain at column 1
117+
118+ Good:
119+
120+ ``` c
121+ #ifdef USE_POSITIVE_NUMBERS
122+ # define A 1
123+ # define B 2
124+ #else
125+ # define A -1
126+ # define B -2
127+ #endif
128+ ```
129+
130+ Bad:
131+
132+ ``` c
133+ #ifdef USE_POSITIVE_NUMBERS
134+ #define A 1
135+ #define B 2
136+ #else
137+ #define A -1
138+ #define B -2
139+ #endif
140+ ```
141+
110142## Formatting
111143
112144### General Rules
@@ -2428,6 +2460,7 @@ This convention system creates self-documenting code where the naming pattern im
24282460| ------| -------------| ---------|
24292461| Braces | K&R variant (new line for functions/types) | ` void f(void)\n{ ` |
24302462| Indentation | 4 spaces, no tabs | ` if (x) { ` |
2463+ | Preprocessor indent | After hash, except include guards | ` #ifdef X\n# define Y 1\n#endif ` |
24312464| Pointer ` * ` | With variable name | ` char *name ` not ` char* name ` |
24322465| Line length | < 100 columns | Use intermediate variables |
24332466| Hex numbers | Uppercase letters | ` 0xDEADBEEF ` not ` 0xdeadbeef ` |
@@ -2739,7 +2772,9 @@ This style guide can be largely enforced using clang-format. Create a `.clang-fo
27392772
27402773BasedOnStyle : LLVM
27412774
2742- # Indentation (rules: AVMCCS-F003)
2775+ # Indentation (rules: AVMCCS-F003, AVMCCS-F022)
2776+ IndentPPDirectives : AfterHash
2777+ PPIndentWidth : -1
27432778IndentWidth : 4
27442779TabWidth : 4
27452780UseTab : Never
@@ -3423,6 +3458,7 @@ This section provides a complete index of all rules defined in this style guide,
34233458| AVMCCS-F019 | Use uppercase letters for hexadecimal numbers | Spacing |
34243459| AVMCCS-F020 | Use spaces around binary operators | Spacing |
34253460| AVMCCS-F021 | Always place initializer braces on the same line as declaration | Spacing |
3461+ | AVMCCS-F022 | Indent nested preprocessor directives after the hash mark | Style Rules |
34263462| **Naming** | | |
34273463| AVMCCS-N001 | Preserve word boundaries when converting between casing styles | Word Boundary Preservation |
34283464| AVMCCS-N002 | Keep acronyms capitalized in PascalCase; treat as single word when converting | Word Boundary Preservation |
@@ -3519,8 +3555,16 @@ This section provides a complete index of all rules defined in this style guide,
35193555| AVMCCS-S005 | Group includes by origin with alphabetical ordering | Include Ordering |
35203556| AVMCCS-S006 | Header files match module names using underscores | Header File Naming |
35213557
3558+ ## Changes
3559+
3560+ ### Version 1.1
3561+
3562+ **Preprocessor Indentation** (AVMCCS-F022):
3563+ - Nested preprocessor directives now indent after the hash mark (exception: include guards remain
3564+ unindented for clarity)
3565+
35223566---
35233567
3524- *Document Version*: 1.0
3568+ *Document Version*: 1.1
35253569*Style Guide Name*: AtomVM C Coding Style Guide (AVMCCS Guide)
3526- *Last Updated*: July 2025
3570+ *Last Updated*: November 2025
0 commit comments