Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!hsi!stpstn!cox From: cox@stpstn.UUCP (Brad Cox) Newsgroups: comp.software-eng Subject: Re: "Program Proving" Message-ID: <4389@stpstn.UUCP> Date: 21 Mar 90 22:26:26 GMT References: <1990Mar17.063012.24979@agate.berkeley.edu> Reply-To: cox@stpstn.UUCP (Brad Cox) Organization: Stepstone Lines: 38 Apparently you haven't heard that C (and its derivatives, including Objective-C and undoubtedly C++ as well) supports assertion checking. It's called assert(). You will undoubtedly find it in /usr/include/assert.h on your system, or thereabouts. You use it like this #include "assert.h" assert(YES) a = 1; assert(a == 1); The macro generates if (!(1)) { fprintf(stderr, "assertion failure in file %s line %d\n", _FILE_, _LINE_); exit(1); } a = 1; if (!(a == 1)) { fprintf(stderr, "assertion failure in file %s line %d\n", _FILE_, _LINE_); exit(1); } But if you set the macro variable, NDEBUG, the assert()s vanish at compile time, so they can be left in the source forever as documentation. By the way, I recommend that the macro be modified to generate as follows, for reasons that should become obvious once you start using it a lot. if (!(a == 1)) assertionFailure(_FILE_, _LINE_); This has proven so useful for C code in general, and for polymorphic object-oriented Objective-C code in particular, that assertion-checking has become a habit, something that we take for granted that any professional programmer would be using as a matter of routine. Wonder why the existence of this macro comes as a surprise to so many. I've even heard assertion checking used as a selling point for Eiffel!