Mailing List Archive

Support open source code!


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

Re: tlug: GCC compiler question



Stephen J. Turnbull wrote:

[snip]
> and might or might not cause a syntax error depending on whether the
> caller's intention was
> 
>      if (true)
>         spin_lock_init(x);
>      else
>         { ... }
> 
> (which generates an "unmatched else" syntax error) or not.  Neither of
> Neil's alternatives work intuitively here.

Yes, the "if...else" construct I hadn't thought of, and is what deems
the "do..while(0)" necessary I guess.

Interestingly, now I start to understand the logic of the semicolon in
Pascal, where said problem wouldn't arise, and my {(x)->lock = 0;} would
work in all cases. I remember when I learnt Pascal (Delphi), I always
found the omission of the ";" before else statements confusing and a
PITA, coming from C.

This little exercise has taught me that Pascal is the logically correct
grammar, and C the dubious one.

Thanks Stephen,

Neil.
---------------------------------------------------------------
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