Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with this macro?

Tags:

c

macros

I am facing a problem with a macro and I can't figure out why.

Here is the macro :

#define WAIT(condition, max_time)               \
   do {                                         \
      int int_loop_wait=0;                      \
      while(1)                                  \    
      {                                         \           
        if(condition) { break; }                \
        sleep(1);                               \
        if(int_loop_wait>=max_time) { break; }  \
        int_loop_wait++;                        \
      }                                         \
    } while(0)                                  \

I got the error

"expected a declaration" line " if(condition) { break; } "

Does anyone understand this error?

like image 910
Joze Avatar asked Mar 26 '13 11:03

Joze


1 Answers

remove the \ from the last line

I mean change this line

 } while(0)                                                     \

by

 } while(0)

And remove all spaces after the \

you have some lines which contain spaces after the \ like:

while(1)                                  \    
      {                                         \           
like image 171
MOHAMED Avatar answered Nov 15 '22 16:11

MOHAMED