Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2001-09-24 18:57:19


on 9/24/01 2:37 PM, Gennadiy E. Rozental at rogeeff_at_[hidden] wrote:

> --- 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.

How? (And in what circumstances is it better than using "goto" directly?)

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

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