MC++D Chapter 1: STATIC_CHECK

Discussion in 'C++' started by LRS Kumar, Dec 21, 2004.

  1. LRS Kumar

    LRS Kumar Guest

    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
    LRS Kumar, Dec 21, 2004
    #1
    1. Advertising

  2. 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
    Karl Heinz Buchegger, Dec 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alf P. Steinbach
    Replies:
    25
    Views:
    979
    Thomas Hansen
    Apr 11, 2005
  2. Steven T. Hatton
    Replies:
    12
    Views:
    532
    Steven T. Hatton
    May 26, 2005
  3. alex

    About STATIC_CHECK macro

    alex, May 31, 2005, in forum: C++
    Replies:
    4
    Views:
    1,574
  4. Herrcho
    Replies:
    6
    Views:
    447
    Peter Pichler
    Feb 20, 2004
  5. Peter Hansen
    Replies:
    2
    Views:
    902
    yaipa h.
    Jun 27, 2003
Loading...

Share This Page