Differences
This shows you the differences between two versions of the page.
| |
| c-do-while-0 [August 22, 2026 at 15:22] – created - external edit 127.0.0.1 | c-do-while-0 [August 22, 2026 at 16:03] (current) – Ivan Janevski |
|---|
| # C do-while-0 | # C do-while-0 |
| |
| **[do { ... } while (0)](https://stackoverflow.com/questions/2381300/what-does-do-while-0-do-exactly-in-kernel-code)** is a C idiom that executes a block exactly once while appearing syntactically like a loop. Compilers optimize it away completely, producing no extra machine code. It's commonly used in [[function-macro|function macros]] to safely wrap multiple statements and enforce semicolon syntax. | **[do { ... } while (0)](https://stackoverflow.com/questions/2381300/what-does-do-while-0-do-exactly-in-kernel-code)** is a C idiom that executes a block exactly once while appearing syntactically like a loop. Compilers optimize it away completely, producing no extra machine code. It's commonly used in [[c-function-macro|function macros]] to safely wrap multiple statements and enforce semicolon syntax. |
| |
| Use `do-while(0)` in macros to enable safe statement grouping and prevent control flow issues. | Use `do-while(0)` in macros to enable safe statement grouping and prevent control flow issues. |