For the More Curious: Assertions

Assertions are a programming technique where tests are added for conditions that cannot happen. The program kills itself when it enters such an impossible state, dumping a core file if it can.

The assert macro

assert (expression)

evaluates the expression. If the expression is zero (false), the process is terminated, a diagnostic message is written to the standard error stream, and the abort() function is called, which terminates the program by raising the signal SIGABRT. Because most programmers use asserts for debugging purposes, you can compile them out of a production program by using the preprocessor flag -DNDEBUG. Be aware of side effects due to code called in the assert() macro. This could cause your program ...

Get Advanced Mac OS X Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.