dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #06771
Re: A general comment on bugs with uninitialized vectors
2008/3/25, Martin Sandve Alnæs <martinal@xxxxxxxxx>:
> 2008/3/25, Johan Hake <hake@xxxxxxxxx>:
>
> > On Tuesday 25 March 2008 13:38:22 Martin Sandve Alnæs wrote:
>
> > > But what's the point of the "do { ... } while(false);" ??
> > > { ... } or just ... should be the same thing as far as I can see.
> >
> >
> > It's because macros are evil! :)
> >
> > http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.4
> >
> > It looks like macros with if statements have a risk of nesting with the wrong
> > if, if it is used inside an other if statement. (Nice sentence! :) )
>
>
> Yes, but a simple {} should do the trick to define a local scope. No
> need for do-while.
I stand corrected... Turns out this was the "naive solution", here's
the explanation:
The naive solution is to wrap the statements inside {...}, such as this:
#define MYMACRO(a,b) \ (Bad)
{ \
statement1; \
statement2; \
... \
statementN; \
}
But this will cause compile-time errors with things like the following:
if (whatever)
MYMACRO(foo, bar);
else
baz;
since the compiler will see a } ; else which is illegal:
if (whatever)
{
statement1;
statement2;
...
statementN;
}; // ERROR: can't have }; before else
else
baz;
--
Martin
Follow ups
References