Sto usando la macro NSAssert per l'asserzione Objective-C, ed è il modo normale per farlo. Ma non funziona nelle funzioni C. Cosa dovrei usare per questo?Qual è il modo normale di affermazione in C?
5
A
risposta
7
NSCAssert()
(e anche NSCAssert1()
, ... fino a NSCAssert5()
)
11
#include <assert.h>
...
assert(<expression>);
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.
Esempio:
assert(x != 0);
nota: Includere assert.h
Nota anche http://vgable.com/blog/2008/12/04/nsassert-considered-harmful per 'assert (x! = 0 &&" quale hey? ")' ... cose interessanti . –