while(0) ?
-
useless so... but avoid using such a macro in your code...
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -
The do/while is there to provide a block. Without the do/while, this code:
if (somefunc())
R(a,b,c);wouldn't give the right behavior because only the first statement would be inside the if block. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
The do/while is there to provide a block. Without the do/while, this code:
if (somefunc())
R(a,b,c);wouldn't give the right behavior because only the first statement would be inside the if block. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
but it could have provided these instructions into a block (
{ }
) without do/while...#define R(l,r,i) { l ^= p[i]; r ^= F(l); }
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 4:49 Wednesday 8th February, 2006 -
but it could have provided these instructions into a block (
{ }
) without do/while...#define R(l,r,i) { l ^= p[i]; r ^= F(l); }
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...] -- modified at 4:49 Wednesday 8th February, 2006Not in all cases. Here's two versions of a macro:
#define FOO1(n) { return n; } #define FOO2(n) do { return n; } while(0)
Now given these two macros this will not complile:if ( 1 ) FOO1(1); else return 0;
But this will:
if ( 1 ) FOO2(1); else return 0;
So there is method to the madness. Steve
-
Not in all cases. Here's two versions of a macro:
#define FOO1(n) { return n; } #define FOO2(n) do { return n; } while(0)
Now given these two macros this will not complile:if ( 1 ) FOO1(1); else return 0;
But this will:
if ( 1 ) FOO2(1); else return 0;
So there is method to the madness. Steve
:-O oh, my mistake... yeah, the problem comes from the
**;**
following the expansion of the macro... a ; cannot come just after a } (except in a user-defined type definition - class, struct, enum, union...)
TOXCCT >>> GEII power
[toxcct][VisualCalc 2.20][VCalc 3.0 soon...]