Alex D
Alex D

Reputation: 30485

Advantages of do { } while(0) versus ({ }) in a macro?

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?

Upvotes: 14

Views: 585

Answers (1)

Quentin
Quentin

Reputation: 63154

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

Upvotes: 32

Related Questions