Practical differences between "do {...} while (0)" and "{...} ((void)0)" in macros?
c, macros, syntax
Solution
The practical difference is exactly what you pointed out.
The `do { ... } while (0)` idiom means that the macro can be used in any context that requires a statement.
Your suggested idiom `{ ... } ((void)0)` can be used safely in most contexts that require an expression -- but it can fail if it's used in an unbraced `if` statement.
I can think of no good reason to use an unfamiliar idiom that almost always works, when there's a well known idiom that always works.
Problem
It's common practice in C to use: ``` #define FOO() do { /* body */ } while (0) ``` While this is fine, it's also possible to do: ``` #define FOO() { /* body */ }((void)0) ``` `{...}((void)0)` has many of the same benefits: you can't accidentally merge logic, and a `;` is required at the end of the line, so odd expressions like this don't go by un-noticed: `FOO() else {...}`. The only difference I've noticed is it means you need to use braces in if-statements. ``` if (a) FOO(); else BAR(); ``` Must be written as: ``` if (a) { FOO(); } else { BAR(); } ``` Other then this quirk, it seems to work well, preventing the same kinds of problems `do/while` method is typically used for. Are there any significant differences between the 2 methods? Said differently, if you see a code-base using `{...}((void)0)`, are practical reasons to switch to using `do{..}while(0)`, besides the one difference already noted?