🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1653

Re: ANSI assert

#1653
From: Theo Norvell
Date: Sat, 08 Sep 1990 20:48
37 lines
1665 bytes
In article <1428@proto.COM> joe@proto.COM (Joe Huffman) writes:
>
>either someone overlooked a potential problem or my coding
>style is going to have to be revised (as well as 10's of thousands of lines
>of code). 
> 
>Can anyone shed some light on this for me?
>
>-- 
>joe@proto.com
>FAX: 208-263-8772

No one overlooked this problem.  At the September 88 meeting, this very point
came up in response to a request from a prominent computer scientist who
argued much as do you.  It was decided that the least evil was to insist
that the argument not be evaluated when NDEBUG is not defined.

The reason is that it is quite reasonable for the argument to make no sense
when runtime checking is on.  For instance, it may use virtual variables,
variables that need not exist except for checking purposes, as in
	void root(void)
	{
	    #ifndef NDEBUG
		float x_init = x;
	    #endif
	    assert(x <= 0.0) ;
	    ... code to find square root ...
	    assert(abs(x_init - x*x) <= EPS) ;
	}
Note that root is neatly specified by pre and post conditions.

As has been pointed out, you may write your own assert macro.  May I
suggest

#define assert_and_do(x) ((x) || assert(0))

Theo Norvell                                         norvell@csri.toronto.edu
Technical Details
Message-ID: <1990Sep8.164857.2930@jarvis.csri.toronto.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!csri.toronto.edu!norvell
References: <1428@proto.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!csri.toronto.edu!norvell
From: norvell@csri.toronto.edu (Theo Norvell)
Newsgroups: comp.std.c
Subject: Re: ANSI assert
Keywords: assert, NDEBUG
Message-ID: <1990Sep8.164857.2930@jarvis.csri.toronto.edu>
Date: 8 Sep 90 20:48:57 GMT
References: <1428@proto.COM>
Organization: CSRI, University of Toronto
Lines: 37