Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!uunet!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: ANSI assert Keywords: assert, NDEBUG Message-ID: <13778@smoke.BRL.MIL> Date: 9 Sep 90 21:03:21 GMT References: <1428@proto.COM> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 105 In article <1428@proto.COM> joe@proto.COM (Joe Huffman) writes: > assert(i++ < limit); > assert(tree_init() == OKAY); >My definition of assert with debugging turned off looks like: >#define assert(test) ((void)(test)) Your definition of assert() is not standard conforming. When NDEBUG is defined before inclusion of , the ONLY conforming definition for the assert() macro is #define assert(ignore) ((void)0) I understand why you prefer your style, but X3J11 decided on the above. Thus you need to change your coding style to something like assert(i < limit); ++i; or #ifndef NDEBUG assert(tree_init() == OKAY); #else (void) tree_init(); /* cast is optional; included for "lint" */ #endif By the way, here's my public-domain implementation of section 4.2: SOURCE FOR in the standard C compilation environment: /* -- definitions for verifying program assertions public-domain implementation last edit: 12-Apr-1990 Gwyn@BRL.MIL complies with the following standards: ANSI X3.159-1989 IEEE Std 1003.1-1988 SVID Issue 3 (except for the extra blank in the NDEBUG case) X/Open Portability Guide Issue 3 (ditto) */ #undef assert #ifdef NDEBUG #define assert(ignore) ((void)0) #else /* ! NDEBUG */ #ifdef __STDC__ extern void __assert(const char *, const char *, int); #define assert(ex) ((ex) ? (void)0 : __assert(#ex, __FILE__, __LINE__)) #else /* ! __STDC__ */ extern void __assert(); /* Reiser CPP behavior assumed: */ #define assert(ex) ((ex) ? (void)0 : __assert("ex", __FILE__, __LINE__)) #endif /* __STDC__ */ #endif /* NDEBUG */ SOURCE FOR __assert() in the standard C run-time support library: /* __assert() -- support function for public-domain implementation last edit: 16-Jan-1990 Gwyn@BRL.MIL complies with the following standards: ANSI X3.159-1989 IEEE Std 1003.1-1988 SVID Issue 3 X/Open Portability Guide Issue 3 */ #include extern void abort(); #ifndef __STDC__ #define const /* nothing */ #endif void __assert(expression, filename, line_num) const char *expression, *filename; int line_num; { (void) fprintf(stderr, "assertion failed: %s, file %s, line %d\n", expression, filename, line_num); (void) fflush(stderr); abort(); /* NOTREACHED */ }