Are there any disadvantages to using the former syntax? It seems cleaner and clearer than the latter.
Asked
Active
Viewed 85 times
0
-
2That is a GCC extension. – BLUEPIXY Dec 30 '16 at 19:52
-
3Possible duplicate: http://stackoverflow.com/questions/1067226/c-multi-line-macro-do-while0-vs-scope-block – Unimportant Dec 30 '16 at 19:52
-
@JonnyHenly see http://stackoverflow.com/questions/154136/why-use-apparently-meaningless-do-while-and-if-else-statements-in-c-c-macros – Random Davis Dec 30 '16 at 19:53
-
3Simple answer: do not use macros unless there is no other way. Do not use them out of laziness. Taken *ad infinitum* you will be using them to write your own language. – Weather Vane Dec 30 '16 at 20:03
-
Note that the `do ... while` version of the `#define` **should not** end with a semicolon: the semicolon will be provided by the usage of the macro (as in `if (a != b) MACROCALL(a, b); /* semicolon here */`) – pmg Feb 01 '19 at 15:32
1 Answers
0
({…})
, as BLUEPIXY wrote, is a GCC extension, and as such has the disadvantage of being not portable to different compilers, while the syntax do {…} while(0)
is standard.

Armali
- 18,255
- 14
- 57
- 171