Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!julius.cs.uiuc.edu!wuarchive!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!sdrc!thor!scjones From: scjones@thor.UUCP (Larry Jones) Newsgroups: comp.std.c Subject: Re: ANSI assert Summary: You're living on borrowed time... Keywords: assert, NDEBUG Message-ID: <159@thor.UUCP> Date: 8 Sep 90 18:15:38 GMT References: <1428@proto.COM> Organization: SDRC, Cincinnati Lines: 34 In article <1428@proto.COM>, joe@proto.COM (Joe Huffman) writes: > In the latest version of 'The C User Journal' P.J. Plauger wrote about the > assert 'function' under ANSI C. He outlined various 'sins' of many > implementations of assert and 'blessed' the following version. It appears > to me that this is wrong (it would break nearly all of my code). > > [ Plauger's version which doesn't evaluate the argument when NDEBUG > is defined ] > > My concern is when NDEBUG is defined. I have many places in my code where I > do something like the following: > > assert(i++ < limit); > > or > > assert(tree_init() == OKAY); I take it you haven't compiled this code with very many compilers. As far as I know, assert has always been a macro, and there has never been any guarantee that it's a safe one! Your code is highly non-portable. X3J11 debated long and loud about whether the argument should be evaluated when NDEBUG is defined, but the decision was made that assert under NDEBUG should completely disappear to avoid any performance hits, despite the fact that you lose some error checking (i.e. the code might actually be invalid if NDEBUG wasn't defined). Code with side-effects in an assert argument was generally agreed to be perverse at best. ---- Larry Jones UUCP: uunet!sdrc!thor!scjones SDRC scjones@thor.UUCP 2000 Eastman Dr. BIX: ltl Milford, OH 45150-2789 AT&T: (513) 576-2070 It's going to be a long year. -- Calvin