Boost logo

Boost :

From: Gennadiy E. Rozental (rogeeff_at_[hidden])
Date: 2001-09-24 09:37:56


--- In boost_at_y..., Darin Adler <darin_at_b...> wrote:
> on 9/21/01 2:24 PM, Fernando Cacciola at fcacciola_at_g... wrote:
>
>
> > * What's the idea of the 'do { ... } while ( false ) ; '
construct?
>
> That's a standard C macro idiom for turning a set of statements
into a
> single statement. It prevents problems with hanging ifs. Here's a
simplified
> example.
>
> #define CALL_IF_0(num, func) if (!num) func()
>
> if (b)
> CALL_IF_0(n, f);
> else
> g();
>
> In the code above, the else gets attached to the if statement
inside the
> macro. The do while false idiom fixes this:
>
> #define CALL_IF_0(num, func) do { if (!num) func() } while
(false)
>
> if (b)
> CALL_IF_0(n, f);
> else
> g();
>
> The else gets attached to the proper if.
>

It also could be used to simulate goto behaviour.

Gennadiy.

> -- Darin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk