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.
Make sure that
NDEBUGis not defined, asassertis enabled only in debug build, i.e whenNDEBUGis not defined.From here:
That is, when
NDEBUGis defined,assertis no-op which is what you observe in assembly.