Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Jun 1998 15:27:26 +0930
From:      Greg Lehey <grog@lemis.com>
To:        Chris Csanady <cc@swing.ca.sandia.gov>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: style(9) error?
Message-ID:  <19980605152726.G768@freebie.lemis.com>
In-Reply-To: <199806042122.QAA00625@swing.ca.sandia.gov>; from Chris Csanady on Thu, Jun 04, 1998 at 04:22:22PM -0500
References:  <199806042122.QAA00625@swing.ca.sandia.gov>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980605152726.G768>