Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!ico!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.std.c Subject: Re: ANSI assert Keywords: assert, NDEBUG Message-ID: <18060@haddock.ima.isc.com> Date: 18 Sep 90 19:08:41 GMT References: <1428@proto.COM> <1990Sep8.164857.2930@jarvis.csri.toronto.edu> <8795@cognos.UUCP> Reply-To: karl@kelp.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 25 In article <8795@cognos.UUCP> jimp@cognos.UUCP (Jim Patterson) writes: >In article <1990Sep8.164857.2930@jarvis.csri.toronto.edu> norvell@csri.toronto.edu (Theo Norvell) writes: >>#define assert_and_do(x) ((x) || assert(0)) > >There's a slight problem with this. While it will work, it will print >a rather misleading message... The more serious problem is that it won't work, since void expressions can't be operands of `||'. >It would be better, though more work and potentially less portable, to copy >and modify the definition of assert(). Alternately: #if defined(NDEBUG) #define require(expr) ((void)(expr)) #else #define require(expr) assert(expr) #endif Karl W. Z. Heuer (karl@kelp.ima.isc.com or ima!kelp!karl), The Walking Lint ________ Exercise for the student: does the error message now contain the user's string or the constant "expr"? Prove your answer using 3.8, then check your favorite ANSI compiler to see if it agrees. Be prepared to defend your reasoning in the form of a bug report.