Каков обычный способ утверждения в C? - PullRequest
5 голосов
/ 02 мая 2010

Я использую макрос NSAssert для утверждения Objective-C, и это обычный способ сделать это. Но это не работа в C-функциях. Что я должен использовать для этого?

Ответы [ 3 ]

11 голосов
/ 02 мая 2010
#include <assert.h>

...

assert(<expression>);

( ссылка )

7 голосов
/ 02 мая 2010

NSCAssert() (а также NSCAssert1(), ... до NSCAssert5())

4 голосов
/ 02 мая 2010
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);

примечание : Включить assert.h

...