From owner-freebsd-hackers Thu Jun 4 22:57:43 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id WAA09979 for freebsd-hackers-outgoing; Thu, 4 Jun 1998 22:57:43 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from freebie.lemis.com (freebie.lemis.com [139.130.136.133]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id WAA09914 for ; Thu, 4 Jun 1998 22:57:30 -0700 (PDT) (envelope-from grog@freebie.lemis.com) Received: (from grog@localhost) by freebie.lemis.com (8.9.0/8.9.0) id PAA03337; Fri, 5 Jun 1998 15:27:27 +0930 (CST) Message-ID: <19980605152726.G768@freebie.lemis.com> Date: Fri, 5 Jun 1998 15:27:26 +0930 From: Greg Lehey To: Chris Csanady , freebsd-hackers@FreeBSD.ORG Subject: Re: style(9) error? References: <199806042122.QAA00625@swing.ca.sandia.gov> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.91.1i In-Reply-To: <199806042122.QAA00625@swing.ca.sandia.gov>; from Chris Csanady on Thu, Jun 04, 1998 at 04:22:22PM -0500 WWW-Home-Page: http://www.lemis.com/~grog Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. > I always thought that blocks evaluated to their last statements, but > it seems not.. Not in C. You might be thinking of Algol 68 or LISP. So what's the real problem? You infer that gcc doesn't like it. It compiles the following quite happily: #define MACRO(x, y) do { \ variable = (x) + (y); \ (y) += 2; \ } while(0) foo () { int variable; int dummyy; MACRO (3, variable); } Greg -- See complete headers for address and phone numbers finger grog@lemis.com for PGP public key To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message