Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > MC++D Chapter 1: STATIC_CHECK

Reply
Thread Tools

MC++D Chapter 1: STATIC_CHECK

 
 
LRS Kumar
Guest
Posts: n/a
 
      12-21-2004
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
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      12-21-2004
LRS Kumar wrote:
>
> 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.

--
Karl Heinz Buchegger
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About STATIC_CHECK macro alex C++ 4 06-01-2005 01:59 AM
70-315: Lab of Chapter 5 =?Utf-8?B?SmFja0JpZ01hYw==?= MCSD 0 02-23-2005 05:35 PM
70-305, Chapter 5 (ADO): Login failed Irene MCSD 9 02-13-2004 03:50 AM
Cisco Networking Simplified - book review and a sample chapter Michael Cisco 0 11-19-2003 11:09 PM
107-188 class, Chapter 1 Step 5 Hallema Morgan Microsoft Certification 0 08-26-2003 11:26 PM



Advertisments