我正在使用NSAssert宏进行Objective-C断言,这是执行此操作的常规方法。 但它在C函数中不起作用。我该怎么用呢?
答案 0 :(得分:11)
#include <assert.h>
...
assert(<expression>);
答案 1 :(得分:7)
NSCAssert()
(以及NSCAssert1()
,......最多NSCAssert5()
)
答案 2 :(得分:4)
void assert(int expression); If expression evaluates to 0 (false), then the expression, source code filename, and line number are sent to the standard error, and then calls the abort function. If the identifier NDEBUG ("no debug") is defined with #define NDEBUG then the macro assert does nothing.
示例:
assert(x != 0);
note :包含assert.h