A version of assert.h which abort()s

Richard O'Keefe ok at edai.UUCP
Wed Apr 11 10:27:16 AEST 1984


I've never found assert(3X) very useful as a debugging tool, as
when an assertion fails, I'd like to get a core dump so I can
poke around with sdb or adb.  This version calls abort() instead
of calling exit(1).

cat >assert.h <<'EOF'
#if	NDEBUG
#   define assert(expression) {}
#else  ~NDEBUG
#   define assert(expression) {if (!(expression)) {\
		fprintf(stderr,"Assertion failed: file %s, line %d\n",\
			__FILE__, __LINE__);\
		abort();}}
#endif	NDEBUG
'EOF'



More information about the Comp.sources.unix mailing list