assert
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <cassert>
|
||
| #ifdef NDEBUG #define assert(condition) ((void)0) |
||
依赖于另一个宏,
assert,这是没有定义的标准库中定义的宏NDEBUG.Original:
The definition of the macro
assert depends on another macro, NDEBUG, which is not defined by the standard library.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
NDEBUG是
<cassert>是包括在源代码中的点定义为宏的名称,然后assert一无所有Original:
If NDEBUG is defined as a macro name at the point in the source code where
<cassert> is included, then assert does nothing.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
NDEBUG没有定义,然后
assert检查,如果其参数(必须有标量类型)比较等于零。如果是的话,assert输出实现特定的标准错误输出的诊断信息,并调用std::abort。需要的诊断信息,包括文本expression,以及价值观的标准宏__FILE__,__LINE__和标准的变量__func__.Original:
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__.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| condition | - | 标量类型的表达
Original: expression of scalar type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[编辑] 返回值
(无)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
Output:
Execution continues past the first assert test: test.cc:8: int main(): Assertion `2+2==5' failed. Aborted
[编辑] 另请参阅
| 静态断言 | 检查(C++11 起)进行编译时断言
Original: performs compile-time assertion checking (C++11 起) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| 导致程序异常终止(不清洗) Original: causes abnormal program termination (without cleaning up) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数) | |