Please be more specific! Give us a *small* piece of code that "doesn't work" and tell us what doesn't work - compile error? link error? wrong result? no result? Also consider posting your compile log; some assert() problems are caused by debug and optimization levels.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-07-17
assert( <expression> ) ;
If the result of <expression> is non zero (or false for a boolean expression), a debug message is displayed (and execution halts). The message is of the form:
For my wishlist, I would like functionality more like what I'm used to from unix. When I'm running "under a debugger", assert should cause the debugger to receive control so that I can perform stack trace backs and dump variables.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-07-24
I thought that raise(SIGTRAP) might work to invoke the debugger but Windows does not support it.
BTW: where I used exit(1), abort() or raise(SIGABRT) may be more appropriate. Although the results are the same.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i can't make it work.
anyone know how to use it?
Thanks
Stef
Please be more specific! Give us a *small* piece of code that "doesn't work" and tell us what doesn't work - compile error? link error? wrong result? no result? Also consider posting your compile log; some assert() problems are caused by debug and optimization levels.
assert( <expression> ) ;
If the result of <expression> is non zero (or false for a boolean expression), a debug message is displayed (and execution halts). The message is of the form:
"Assertion failed: <expression>, <sourcefile>, <linenum>"
assert has no effect if NDEBUG is defined.
Unfortunately in a console app, because the program terminates, its window closes immediatly. Run the code form a command line window to prevent this.
Alternatively assert is a macro not a function, which means you can modify it or write your own. This is my solution to the window closing problem:
#if !defined NDEBUG
#include <stdio.h>
#undef assert
#define assert(e) if(e){ printf( "Assertion failed: %s %s:%d", #e, __FILE__, __LINE__); \
getchar() ; exit(1); }
#else
#define assert(e)
#endif
Place this in a header called <debug.h> for example, and include it where necessary.
Clifford
Clifford -- thanks for the nice write up.
For my wishlist, I would like functionality more like what I'm used to from unix. When I'm running "under a debugger", assert should cause the debugger to receive control so that I can perform stack trace backs and dump variables.
I thought that raise(SIGTRAP) might work to invoke the debugger but Windows does not support it.
BTW: where I used exit(1), abort() or raise(SIGABRT) may be more appropriate. Although the results are the same.
Clifford