assert
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <cassert> 中定义
|
||
| #ifdef NDEBUG #define assert(condition) ((void)0) |
||
依赖于另一个宏,
assert,这是没有定义的标准库中定义的宏NDEBUG.原文:
The definition of the macro
assert depends on another macro, NDEBUG, which is not defined by the standard library.NDEBUG是
<cassert>是包括在源代码中的点定义为宏的名称,然后assert一无所有原文:
If NDEBUG is defined as a macro name at the point in the source code where
<cassert> is included, then assert does nothing.NDEBUG没有定义,然后
assert检查,如果其参数(必须有标量类型)比较等于零。如果是的话,assert输出实现特定的标准错误输出的诊断信息,并调用std::abort。需要的诊断信息,包括文本expression,以及价值观的标准宏__FILE__,__LINE__和标准的变量__func__.原文:
If NDEBUG is not defined, then
assert checks if its argument (which must have scalar type) compares equal to zero. If it does, assert outputs implementation-specific diagnostic information on the standard error output and calls std::abort. The diagnostic information is required to include the text of expression, as well as the values of the standard macros __FILE__, __LINE__, and the standard variable __func__.目录 |
[编辑] 参数
| condition | - | 标量类型的表达
|
[编辑] 返回值
(无)
[编辑] 示例
输出:
Execution continues past the first assert test: test.cc:8: int main(): Assertion `2+2==5' failed. Aborted
[编辑] 另请参阅
| 静态断言 | 检查(C++11 起)进行编译时断言
原文: performs compile-time assertion checking (C++11 起) |
| 导致程序异常终止(不清洗) 原文: causes abnormal program termination (without cleaning up) (函数) | |