C – Advantages of do { } while(0) Versus ({ }) in a Macro

c++macros

There are plenty of questions on Stack Overflow regarding the use of do { ... } while(0) in macros, but this is a bit different. I understand why do { ... } while(0) is used to wrap multiple lines of code in a macro expansion. But there is another form I often see: ({ ... }).

The ({ }) form has the advantage that it is an expression and can have a "return value". It also (subjectively) reads better than do { } while(0). So why isn't it always used? What advantage is there to using do { } while(0) in a macro instead?

Best Answer

Because ({...}) is a GCC extension.