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

I look at a third-party code base and see this assert macro definition:

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

What is the meaning of (void)1 ? How is it better than idiomatic (void)0 ?

+4
source share
2 answers

There is no difference between (void)1 and (void)0 .

+4
source

I think this is not so important (and will be optimized by the compiler). And <cassert> is the standard C ++ header (using the standard <assert.h> C header) that defines the standard assert macro, so the application should not override it.

+4
source

Source: https://habr.com/ru/post/1379280/


All Articles