Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在 MSFT Visual Studio 2010 Beta 上编写 C89。如何进行断言,类似于 Java 的assert关键字?我想我需要定义一个宏,但我不确定如何。(这似乎是以前做过的事情,所以我宁愿使用它也不愿尝试自己动手。)
assert
这是一个猜测:
int assert(int truth_value) { // crash the program with an appropriate error message }
C89 has <assert.h>,其中包含您要查找的宏。
<assert.h>
#include <assert.h> assert(expression);
从文档中:
assert () 宏测试给定的表达式,如果为假,则终止调用进程。将诊断消息写入stderr 并调用 abort(3) 函数,从而有效地终止程序。 如果表达式为真,assert () 宏什么也不做。
assert () 宏测试给定的表达式,如果为假,则终止调用进程。将诊断消息写入stderr 并调用 abort(3) 函数,从而有效地终止程序。
如果表达式为真,assert () 宏什么也不做。