473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Loki's STATIC_CAST macro

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
Jul 22 '05 #1
1 2378

"LRS Kumar" <lr******@yahoo.co.in> wrote in message
news:d0**************************@posting.google.c om...
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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sebastian Faust | last post by:
Hi, I read about the Loki::Factory and Loki::AbstractFactory in the book Modern C++ Design and couldnt figure out one thing: If I have several classes, for example the following hierarchie: ...
1
by: Dave | last post by:
Is anybody aware of a newsgroup devoted to Loki? I assume this forum would not be the most appropriate place to discuss a specific library, even if that library is written purely in standard...
3
by: Krivenok Dmitry | last post by:
I writing simple class CmdLine: ..... ..... class CmdLine { ..... ..... public: /// Constructor CmdLine(int argc, char** argv);
3
by: Krivenok Dmitry | last post by:
Hello All! This is example of code: ////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef A_H_ #define A_H_ #include <Loki/Singleton.h>...
2
by: Martin Herbert Dietze | last post by:
Hi, in a project I am using callbacks which are called like ordinary functions but in fact are Loki::Functor's encapsulating calls to non-static member functions on instances of different...
10
by: Ray | last post by:
I am reading Andrei Alexandrescu's book. The ideas presented there sound really good, but I wonder--is there really a lot of people using it? Or it's simply too esoteric for mortals? Cheers Ray
10
by: Jim Langston | last post by:
Is the following well defined? size_t IntVal = 65537; unsigned short Length; if ( IntVal static_cast<unsigned short>( -1 ) ) { std::cout << "Value too long to fit in a short" << std::endl;...
2
by: Shawn McGrath | last post by:
Hey, I can't get DeletableSingleton to actually delete the singleton. The code is: typedef Loki::SingletonHolder<GenClass Loki::CreateUsingNew, Loki::DeletableSingletonGen; .......
3
by: aaragon | last post by:
Hello everyone, I've been trying to work with the visitor design pattern, and it works fine except for the following. Let's suppose that we have a fixed hierarchy of classes (many of them)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.