Date: Fri, 05 Jun 1998 11:26:17 +0200 (CEST) From: Marino Ladavac <lada@pc8811.gud.siemens.at> To: Greg Lehey <grog@lemis.com> Cc: freebsd-hackers@FreeBSD.ORG, Chris Csanady <cc@swing.ca.sandia.gov> Subject: Re: style(9) error? Message-ID: <XFMail.980605112617.lada@pc8811.gud.siemens.at> In-Reply-To: <19980605152726.G768@freebie.lemis.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 05-Jun-98 Greg Lehey wrote: > On Thu, 4 June 1998 at 16:22:22 -0500, Chris Csanady wrote: >> >> I would like to make use of a feature that style tells me I can use, but >> gcc tells me I can not.. >> >>> From style(9): >> >> es, it makes it easier to read. If the macro encapsulates a compound >> statement, enclose it in a ``do'' loop, so that it can safely be used >> in >> ``if'' statements. Any final statement-terminating semicolon should be >> supplied by the macro invocation rather than the macro, to make parsing >> easier for pretty-printers and editors. >> >> #define MACRO(x, y) do { >> #\ >> variable = (x) + (y); >> \ >> (y) += 2; >> \ >> } while(0) >> >> As far as I can tell, it is impossible to put a do loop in a if statement, >> or anything else. Is this correct? > > No. We have a case of misunderstanding here: the original poster asked whether if (MACRO(x, y)) foo(); else bar(); were allowed (which it is not, with the MACRO defined as it is), whereas you and the manpage are refering to if (foo()) MACRO(x, y); else MACRO(y, x); which is, and the do {} while() loop MACRO construct is necessary in order to allow for semicolons after the MACRO invocation in a true or false branches of an if statement. /Marino To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.980605112617.lada>