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
  • 330,190
  • 66
  • 504
  • 555
asio_guy
  • 3,524
  • 2
  • 17
  • 34
  • 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