为什么断言定义为(void)0? [英] Why is assert defined as (void)0?

查看:110
本文介绍了为什么断言定义为(void)0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么
#define assert(expression)((void)0)
而不是
#define assert(expression)
是在发布模式下使用的吗?(严格来说,当定义NDEBUG时)

Why #define assert(expression) ((void)0), rather than #define assert(expression) is used in release mode?(strictly speaking, when NDEBUG is defined)

我听说出于某些原因,但是我已经忘记了。

I heard that there are some reasons, but I've forgot it.

推荐答案

((void)0)定义 assert(expression)不执行任何操作。

使用它的主要原因是#定义assert(expression)将允许 assert(expression)进行编译而无需使用分号,但是如果将宏定义为<$ c,则不会进行编译$ c>((void)0)

((void)0) defines assert(expression) to do nothing.
The main reason to use it is that #define assert(expression) would allow assert(expression) to compile without a semicolon but it will not compile if the macro is defined as ((void)0)

这篇关于为什么断言定义为(void)0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆