[英]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: 我正在审查第三方代码库并看到assert
宏的这个定义:
#define assert( x ) \
if( !( x ) ) { \
ThrowException( __FILE__, __LINE__ ); \
} else \
((void)1)
What's the point in (void)1
? (void)1
什么意义? How is it better than idiomatic (void)0
? 它比idiomatic (void)0
更好吗?
(void)1
和(void)0
之间没有区别。
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. <cassert>
是一个标准的C ++头文件(使用标准的<assert.h>
C头文件),它定义了一个标准的assert
宏,因此应用程序不应该重新定义它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.