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. Advertisements

  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. Advertisements

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:
    1,304
    Thomas Hansen
    Apr 11, 2005
  2. Steven T. Hatton
    Replies:
    12
    Views:
    677
    Steven T. Hatton
    May 26, 2005
  3. alex

    About STATIC_CHECK macro

    alex, May 31, 2005, in forum: C++
    Replies:
    4
    Views:
    1,688
  4. Herrcho
    Replies:
    6
    Views:
    607
    Peter Pichler
    Feb 20, 2004
  5. Peter Hansen
    Replies:
    2
    Views:
    1,082
    yaipa h.
    Jun 27, 2003
  6. David MacQuigg

    Intro Chapter on OOP using Prothon

    David MacQuigg, Apr 10, 2004, in forum: Python
    Replies:
    0
    Views:
    316
    David MacQuigg
    Apr 10, 2004
  7. Philip
    Replies:
    1
    Views:
    490
    MooMaster
    Jul 20, 2005
  8. Tom Grove
    Replies:
    4
    Views:
    317
    John Salerno
    Jun 30, 2006
Loading...