eonil
eonil

Reputation: 86165

What's the regular way of assertion in C?

I'm using NSAssert macro for Objective-C assertion, and it's the regular way to do this. But it's not work in C functions. What do I should use for this?

Upvotes: 5

Views: 2800

Answers (3)

newacct
newacct

Reputation: 122538

NSCAssert() (and also NSCAssert1(), ... up to NSCAssert5() )

Upvotes: 7

N 1.1
N 1.1

Reputation: 12544

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.

Example:

assert(x != 0);

note: Include assert.h

Upvotes: 4

Amber
Amber

Reputation: 527548

#include <assert.h>

...

assert(<expression>);

(reference)

Upvotes: 11

Related Questions