C++ General Question - FreeBSD's approach to assert(x != NULL)

C++:
assert(x != NULL);

Am I correct in thinking that the above statement will halt the execution of a compiled binary if x == NULL when the assert code is called?

Does it call any deconstructors, or is it a hard (as in kill -9) approach?

Edit: Also, what is the good practice within FreeBSD base with regards to using assert in code in a production enviroment rather than an if + error handling?

Thanks,
James
 
First of all, assert(3) is C, not C++. This manpage should also answer all your questions. In a nutshell, it's a debugging tool only, will forcefully abort(3) the program without any cleanup (which would be caught by an attached debugger, so you could start analyzing program state right away), and must never be used to check for anything that's expected to happen eventually. An unmet assertion must correlate to a bug in your program.

It's good practice to create release builds with NDEBUG defined, which will remove all assertion checking code.
 
Back
Top