Multi-statement macros (again)
Frank Wales
frankw at hpcvra.CV.HP.COM
Sat Feb 10 09:01:47 AEST 1990
In some article, sullivan at aqdata.uucp (Michael T. Sullivan) wrote:
[an article about writing macros which do things that are forbidden
in expressions, like using return, which concluded with...]
>I then changed BEGIN_ and END_BLOCK to:
>#define BEGIN_BLOCK do { if (1) {
>#define END_BLOCK } } while (0)
>This seems to make everything happy. My question is, will this make other
>machines happy? We are using a 3B2/400 SVR3 and it didn't even complain
>when just braces were used (resulting in "};"). Does this shut everything
>up on YOUR machine?
I have used the do { ... } while(0) trick on many occasions to write macros
which declare temporary variables. This produces a warning of the form
"constant in conditional context" when compiled on an HP9000 PA machine
(s600 or s800), which I live with (a compiler directive to get rid of
it on a case-by-case basis would be useful, but I'm not that bothered;
I would definitely not want an option which just lost all these warnings).
--
Frank Wales, Guest of HP Corvallis, [frank at zen.co.uk||frankw at hpcvdq.cv.hp.com]
Zengrange Ltd., Greenfield Rd., LEEDS, England, LS9 8DB. (+44) 532 489048 x217
More information about the Comp.lang.c
mailing list