MC++D Chapter 1: STATIC_CHECK

L

LRS Kumar

In Chapter 1(Page 25 in my copy) of Modern C++ Design, Alexandrescu
uses a macro called STATIC_CHECK:

#define STATIC_CHECK(expr, msg) \
{\
class ERROR_##msg {};
(void)sizeof((CompileTimeChecker<(expr) !=
0>((ERROR_##msg()))));\
}

Does anyone know why he casts to void?

Thanks.
LRS
 
K

Karl Heinz Buchegger

LRS said:
In Chapter 1(Page 25 in my copy) of Modern C++ Design, Alexandrescu
uses a macro called STATIC_CHECK:

#define STATIC_CHECK(expr, msg) \
{\
class ERROR_##msg {};
(void)sizeof((CompileTimeChecker<(expr) !=
0>((ERROR_##msg()))));\
}

Does anyone know why he casts to void?

Looks to me like the technique used to give a hint
to the compiler, that the non-use of an expression result
is intentional.


eg. in
void foo( int i )
{
i;
}

some compilers will emit a warning:
"statement has no effect, is this intentional?"
or something like that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top