0

I can see the do{}while(0) guard MACRO being extensively used and while some cases it is defined with a ; at the end where as some are defined without a ;

Which one is more correct with ; or without it

#define FOO(x)      \  
do {                \   
     if( x > 0 )    \
          bar(x);   \
     else           \
          done(x);  \
 }while(0); 

or

#define FOO(x)      \  
do {                \   
     if( x > 0 )    \
          bar(x);   \
     else           \
          done(x);  \
 }while(0)
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
asio_guy
  • 3,667
  • 2
  • 19
  • 35
  • in that case you could avoid the do/while by omitting the last ";" after `done(x)` – Jean-François Fabre Jan 04 '18 at 12:54
  • @EdHeal It may be more unreadable, but is safer (without the semicolon on the end). A possible alternative is to replace the macros with static inline functions where possible. – Ian Abbott Jan 04 '18 at 13:00

0 Answers0