Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tlug: GCC compiler question



>#define spin_lock_init(x)       do { (x)->lock = 0; } while(0)
>
>If it were used in the following way:
>
>if (true)
>     spin_lock_init (x);
>
>The semi-colon following "spin_lock_init (x);" will be consumed as
>part of the macro expansion as:
>
>if (true)
>   do { (x)->lock = 0; } while(0);
>
>
>If we were to declare the macro as follows:
>
>#define spin_lock_init(x)       { (x)->lock = 0; }
>
>Then this would expand to  
>
>if (true)
>   { (x)->lock = 0; }

Wouldn't it expand to this?

  if (true)
     { (x)->lock = 0; };

>...and not be syntactically correct, this will cause a compile error as
>no semi-colon is present.

Where is the syntax error?

>#define m(A) if(A){exp1; exp2;}
>
>You can see the problems with the semi-colon when this is expanded,
>we need to wrap it in a "do{ ... } while(0)".

Doesn't "m(myptr);" expand to this?

   if(myptr){exp1; exp2;};


Am I missing something obvious here?

Darren

---------------------------------------------------------------
Next Nomikai: 20 November, 19:30 Tengu TokyoEkiMae 03-3275-3691
Next Meeting: 12 December, 12:30 Tokyo Station Yaesu central gate
---------------------------------------------------------------
Sponsor: PHT, makers of TurboLinux http://www.pht.co.jp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links