Search code examples
c++visual-c++assertno-op

Why use (void)1 as a no-op in C++?


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?


Solution

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