File, line and message for assert(0)?

Michel Fortin michel.fortin at michelf.com
Sat May 28 10:56:46 PDT 2011


On 2011-05-28 12:32:59 -0400, simendsjo <simen.endsjo at pandavre.com> said:

> I don't think I understand the use case for assert(0) then.. I thought 
> it was just a way getting assert in release mode.

The use case for assert(0) is the same as any assert(whatever): 
checking for things that shouldn't happen. Normally compiling in 
release mode would strip all the asserts to make things slimmer and 
faster. But given there is no cost in checking for assert(0), those are 
not stripped, they are just replaced with a halt instruction. So the 
assert's still there, but you don't have a message for it nor the line 
number.

If you want to see where the assertion happens, you can either compile 
in non-release mode or you can hook a debugger to your release 
executable and wait for the assert to happen.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d-learn mailing list