Site Tools


c-do-while-0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c-do-while-0 [August 22, 2026 at 15:22] – created - external edit 127.0.0.1c-do-while-0 [August 22, 2026 at 16:03] (current) Ivan Janevski
Line 1: Line 1:
 # 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.
c-do-while-0.md · Last modified: by Ivan Janevski