assert() function not showing up in disassembly

c++, compiler-construction

Solution

Make sure that `NDEBUG` is not defined, as `assert` is enabled only in debug build, i.e when `NDEBUG` is not defined.

From here:

#ifdef NDEBUG
#define assert(condition) ((void)0)
#else
#define assert(condition) /*implementation defined*/
#endif

That is, when `NDEBUG` is defined, `assert` is no-op which is what you observe in assembly.

Problem

My coworker just asked me to help on a problem, he has a few lines in his code as ``` for (long counter = 0; counter < End; ) { ... assert(counter++ < MAX); ... } ``` The problem is, when we use Visual Studio to debug line by line, seems the assert() line got skipped all the time, and `counter` never got incremented and thus the loop never finished. When we look at the disassembly using VS, there is no assembly line for this assert() function. I never used assert() before, so I'm wondering is this normal and he shouldn't put any code behavior into assert() or something is wrong here with debugger or other? Thanks.

Original source