[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

do ... while(0) in macros

I'd say it's to define a new scoping block so that macros can create
locally scoped variables. I once had a compiler where the
"normal" way of doing this:
#define MY_MACRO(X) {int j; j=3; X=J;}
Didn't work, but
#define MY_MACRO(X) do {int j; j=3; X=J;} while (0)

would work. So RTEM's may do it for similar reasons. ?

Just a guess...


----- Original Message -----
From: <lange92 at 2067.resnet.uni.edu>
To: "CARERI/SED" <careri at public.sta.net.cn>
Cc: <rtems-users at oarcorp.com>
Sent: Tuesday, August 07, 2001 10:15 PM
Subject: Re: do ... while(0) in macros

> Well, I don't profess to know definite RTEMS-specific answers, but as was
> pointed out in one of my classes, a do-while loop always executes at least
> once, even if the condition if false. It executes before evaluation.
> On the other hand, I won't comment on the form, but I do know that it is
> entirely possible in C to redefine 0, potentially producing a loop here
> that executes multiple times.
> DanL
> On Wed, 8 Aug 2001, CARERI/SED wrote:
> > There are many macros in RTEMS written like the following code:
> >
> >   do {
> >   } while (0)
> >
> > Could anybody explain the purpose of the "do ... while(0)" ?