4

I'm reviewing a third party codebase and see this definition of an assert macro:

#define assert( x ) \
     if( !( x ) ) { \
        ThrowException( __FILE__, __LINE__ ); \
     } else \
        ((void)1)

What's the point in (void)1? How is it better than idiomatic (void)0?

sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • 6
    Just a lack of imagination. Replace with (void)42 so its obvious. – Hans Passant Nov 02 '11 at 11:08
  • 1
    This is special: http://www.google.com/codesearch#nJHaZQ1IJ84/trunk/third_party/spidermonkey/js/src/jsdhash.c&q=%22%28void%291%22&type=cs, it uses `(void)1` and `(void)0`. Perhaps to distinguish between the two when examining preprocessed output? – Steve Jessop Nov 02 '11 at 12:21

2 Answers2

4

There's no difference between (void)1 and (void)0.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
4

I think it does not matter that much (and will be optimized away by the compiler). And <cassert> is a standard C++ header (using the standard <assert.h> C header) which defines a standard assert macro, so an application should not re-define it.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547