Date: Fri, 13 Mar 1998 12:13:30 +0100 From: Eivind Eklund <eivind@yes.no> To: shimon@simon-shapiro.org, freebsd-current@FreeBSD.ORG Subject: Re: A question about sys/sys/queue.h Message-ID: <19980313121330.54903@follo.net> In-Reply-To: <XFMail.980312191745.shimon@simon-shapiro.org>; from Simon Shapiro on Thu, Mar 12, 1998 at 07:17:45PM -0800 References: <XFMail.980312191745.shimon@simon-shapiro.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 12, 1998 at 07:17:45PM -0800, Simon Shapiro wrote:
> Why was the definition of some macros changed
> from:
>
> #define FOO(a) { ... }
>
> to:
>
> #define FOO(a) do { ... } while(0)
>
> I thought these are the same...
Imagine these used in a dual if () statement:
if (bar)
if (baz)
FOO(1);
else
printf ("You loose!\n");
With the former, you get something that (with proper indentation) map
as
if (bar)
if (baz)
{ ... };
else
printf ("You loose!\n");
while with the do {...} while (0) trick, you get
if (bar)
if (baz)
do { ... } while(0);
else
printf ("You loose!\n");
For any onlookerss: You can't get the correct binding with if ()
tricks, BTW. Stick with the good old "do { ... } while(0)"
Eivind.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980313121330.54903>
