January 2020
Intermediate to advanced
454 pages
11h 25m
English
The NDEBUG macro originates from C and was used to change the behavior of the assert() function. The assert() function can be written as follows:
void __assert(int val, const char *str){ if (val == 0) { fprintf(stderr, "Assertion '%s' failed.\n", str); abort(); }}#ifndef NDEBUG #define assert(a) __assert(a, #a)#else #define assert(a)#endif
As shown in the preceding code, if the __assert() function is given a Boolean that evaluates to false (written in C, this is an integer that is equal to 0), an error message is outputted to stderr and the application is aborted. The NDEBUG macro is then used to determine whether the assert() function exists, and if the application is in release mode, then all of the assert logic is removed, ...