@@ -40,12 +40,12 @@ These rules are unique to Zen C. Each rule is checked when `--misra` is active.
4040Forbids ` raw { } ` blocks that bypass the transpiler.
4141
4242``` zc
43- // ❌ Violation :
43+ // Bad :
4444fn main() {
4545 raw { int x = 10; }
4646}
4747
48- // ✅ Fix: use native Zen C constructs
48+ // Good:
4949fn main() {
5050 let x = 10;
5151}
@@ -56,10 +56,10 @@ fn main() {
5656Forbids ` plugin ... end ` blocks, which execute arbitrary build-time code.
5757
5858``` zc
59- // ❌ Violation :
59+ // Bad :
6060plugin my_plugin
6161
62- // ✅ Fix: implement functionality as a regular function or import a library
62+ // Good:
6363import "std/some_module.zc"
6464```
6565
@@ -70,16 +70,15 @@ Forbids the `_` wildcard in `match` on enum types -- all variants must be handle
7070``` zc
7171enum Color { Red; Green; Blue; }
7272
73- // ❌ Violation :
73+ // Bad -- missing Blue :
7474fn describe(c: Color) {
7575 match c {
7676 Color::Red => { println "red"; }
7777 Color::Green => { println "green"; }
78- // Missing Blue -- Zen 1.3
7978 }
8079}
8180
82- // ✅ Fix: handle all variants
81+ // Good:
8382fn describe(c: Color) {
8483 match c {
8584 Color::Red => { println "red"; }
@@ -95,11 +94,11 @@ Forbids C preprocessor directives (`#define`, `#include`, `#if`, etc.).
9594Use Zen's ` import ` and ` def ` instead.
9695
9796``` zc
98- // ❌ Violation :
97+ // Bad :
9998#define BUFFER_SIZE 256
10099#include <stdio.h>
101100
102- // ✅ Fix :
101+ // Good :
103102def BUFFER_SIZE = 256;
104103import "std/io.zc"
105104```
@@ -110,31 +109,30 @@ The `var` and `const` keywords are deprecated for variable/constant declarations
110109Use ` let ` for variables and ` def ` for compile-time constants.
111110
112111``` zc
113- // ❌ Violation :
112+ // Bad :
114113var x = 10;
115114const MAX = 100;
116115
117- // ✅ Fix :
116+ // Good :
118117let x = 10;
119118def MAX = 100;
120119```
121120
122- > The ` const ` keyword remains valid as a ** type qualifier** for C interop
123- > (e.g., ` const int ` means "pointer to const int" in FFI declarations).
121+ > ` const ` remains valid as a ** type qualifier** for C interop
122+ > (e.g., ` const int ` in FFI declarations).
124123
125124#### Zen 1.8 -- No identifier shadowing
126125
127126Forbids declaring a name that hides one from an outer scope.
128127
129128``` zc
130- // ❌ Violation:
131129let x = 10;
132130if true {
133- let x = 20; // shadows outer x
131+ // Bad -- shadows outer x:
132+ let x = 20;
134133}
135134
136- // ✅ Fix: use a distinct name
137- let x = 10;
135+ // Good:
138136if true {
139137 let inner_x = 20;
140138}
@@ -146,12 +144,12 @@ Forbids identifiers starting with `__`, `_[A-Z]`, or `_z_`, which are reserved
146144for the compiler and C implementation.
147145
148146``` zc
149- // ❌ Violation :
147+ // Bad :
150148let __my_var = 10;
151149let _Reserved = 20;
152150let _z_internal = 30;
153151
154- // ✅ Fix: use non-reserved names
152+ // Good:
155153let my_var = 10;
156154let reserved = 20;
157155let internal = 30;
@@ -163,17 +161,15 @@ Tuples with **3 or more fields** shall not be used as function return types or
163161parameters. Use a named struct instead. 2-tuples are exempt.
164162
165163``` zc
166- // ❌ Violation :
164+ // Bad -- 3-tuple as return type :
167165fn get_stats() -> (int, int, int) { ... }
168-
169- // ❌ Violation:
170166fn process(p: (int, string, bool)) { ... }
171167
172- // ✅ OK :
168+ // Good -- use a struct :
173169struct Stats { sum: int; avg: int; max: int; }
174170fn get_stats() -> Stats { ... }
175171
176- // ✅ OK ( 2-tuples exempt) :
172+ // OK -- 2-tuples are exempt:
177173fn get_pair() -> (int, int) { ... }
178174```
179175
@@ -182,14 +178,14 @@ fn get_pair() -> (int, int) { ... }
182178` string == string ` shall not be used. Use ` strcmp() ` instead.
183179
184180``` zc
185- // ❌ Violation :
186- if a == b { ... } // when a, b are string
181+ // Bad (when a, b are string) :
182+ if a == b { ... }
187183
188- // ✅ Fix :
184+ // Good :
189185if strcmp(a, b) == 0 { ... }
190186
191- // ✅ OK (non-string types) :
192- if x == y { ... } // int, bool, pointer comparisons are safe
187+ // OK -- int, bool, pointer comparisons are safe :
188+ if x == y { ... }
193189```
194190
195191## Standard MISRA C:2012 Coverage
0 commit comments