[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Setter Gettor method style
From: |
Bissell, Tim |
Subject: |
RE: Setter Gettor method style |
Date: |
Mon, 5 Aug 2002 15:50:45 +0100 |
> From: Pascal Bourguignon [mailto:pjb@informatimago.com]
[...]
> > From: Martin =?iso-8859-1?Q?H=E4cker?= <mhaecker@mac.com>
> > Date: Mon, 5 Aug 2002 00:32:27 +0200
> >
> > >The '({' stuff is a gcc extension; 'do {...} while(0)' is portable.
> >
[...]
> In this particular case, it's just syntactic sugar that don't change
> anything to the generated code. So I would say, stick with the
> compatible do{...}while(0).
This is not strictly speaking true; ({... }) is a gcc extension which
allows you to wrap a code fragment which returns a value, inside a C
expression.
do { ... } while (0) is not a C expression, it is a C statement,
so they are not equivalent.
Specifically, if I define:
#define FOO(X) ({ int result = (X); \
if (result > 32 || result < 16) result = 9; result; })
I can go:
{
int x = ....;
if (FOO(x) == 12) { .... do something .... }
}
but a definition of:
#define FOO(X) do { int result = (X); \
if (result > 32 || result < 16) result = 9; result; }
while (0);
will generate syntax errors in the compiler...
----------------------------------------------------------------------
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.drkw.com/disc/email/ or contact the sender.
----------------------------------------------------------------------