red floyd wrote:
Mike Smith wrote: Steven T. Hatton wrote:
I've noticed in different places where people who write #MACROS use a
null
do/while. For example:
do { POINTER = new CONSTRUCTOR; \
if (POINTER == 0) { errno = ENOMEM; ACE_THROW_INT (EXCEPTION); }
\
} while (0)
What does that accomplish?
This to to allow a block/multiline macro that is safe to use in an
IF-ELSE construct.
#define MACRO() do { /* something */; } while (0)
///
if (condition)
MACRO();
else
{
// do something else
}
now, consider the above code with the following definition
#define MACRO() { /* something */ ; }
Now how would it expand out?
The do { } while (0) construct provides a block that must be terminated
by a semicolon.
Yeah, I was a bit slow on the uptake, but Victor and Artie cleared it up for
me. I'm specifically curious about the "ability to break out" comment from
Mike Smith, which I still don't understand.
BTW, I hope people don't think my dislike and objection to the CPP is
unqualified. I /do/ understand where it is useful, and why people like it.
It does "cookiecutt er" work, among other things. The two most useful
functions I've seen for the CPP are selfreferential source extraction, and
conditional compilation.
WTH does "selfreferentia l source extraction" mean? It means grabbing some
text from the source code to be included in the compiled program. E.g.,
class names, function names, variable names etc.
I don't believe I need to define conditional compilation. I will, however,
say it is a rather ugly feature of C++ in so much as it often breaks up the
flow of a program into difficult to follow slices. I wonder if an internal
language construct such as compile_if(bool condition){} might prove
superior.
I'm gonna stick this in the thread about the study of the CPP, but I figure
it may be worth including here:
http://etheses.uwaterloo.ca/display.cfm?ethesis_id=390
I've only skimmed it.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell