Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!pasteur!helios.ee.lbl.gov!ucsd!ucsdhub!hp-sdd!hp-pcd!hpcvra!frankw From: frankw@hpcvra.CV.HP.COM (Frank Wales) Newsgroups: comp.lang.c Subject: Re: Multi-statement macros (again) Message-ID: <17000001@hpcvra.CV.HP.COM> Date: 9 Feb 90 22:01:47 GMT References: <1990Feb8.235051.21779@aqdata.uucp> Organization: Hewlett-Packard Co., Corvallis, OR, USA Lines: 23 In some article, sullivan@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@zen.co.uk||frankw@hpcvdq.cv.hp.com] Zengrange Ltd., Greenfield Rd., LEEDS, England, LS9 8DB. (+44) 532 489048 x217