Loki's STATIC_CAST macro

L

LRS Kumar

In Chapter 2 of MC++D, Andrei Alexandrescu introduces a macro called
STATIC_CAST. Here is the source related to it:


#ifndef STATIC_CHECK_INC_
#define STATIC_CHECK_INC_

namespace Loki
{

template<int> struct CompileTimeError;
template<> struct CompileTimeError<true> {};
}

#define STATIC_CHECK(expr, msg) \
{ Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }



#endif // STATIC_CHECK_INC_


I would be grateful if someone could explain to me the reason for the last line
of STATIC_CAST (the cast to void):
(void)ERROR_##msg;

STATIC_CAST seems to be doing its job even without this line. So why is it
needed?

Cheers,
LRS
 
J

John Harrison

LRS Kumar said:
In Chapter 2 of MC++D, Andrei Alexandrescu introduces a macro called
STATIC_CAST. Here is the source related to it:
STATIC_CHECK



#ifndef STATIC_CHECK_INC_
#define STATIC_CHECK_INC_

namespace Loki
{

template<int> struct CompileTimeError;
template<> struct CompileTimeError<true> {};
}

#define STATIC_CHECK(expr, msg) \
{ Loki::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; }



#endif // STATIC_CHECK_INC_


I would be grateful if someone could explain to me the reason for the last line
of STATIC_CAST (the cast to void):
(void)ERROR_##msg;

STATIC_CAST seems to be doing its job even without this line. So why is it
needed?

To me it looks like an attempt to avoid 'unused variable' type warning
messages when using STATIC_CHECK.

john
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top