Peter N Lewis wrote:
These are the three I use to build my C99 assert() function and some other tracing stuff.
It's not really necessary. GPC has a built-in `Assert' procedure which in case of failure gives a regular runtime error.
Yes, but my reading of this was that it could not be compiled out (turned off, but not compiled out), which is insufficient - it does not properly encourage asserting *everything* which (IMO, as well as Steve Maguire's, see Writing Solid Code which is a very good book (despite coming from Microsoft)). As much as possible I assert every precondition on entry and every post condition on exit to procedures, as well as asserting the validity of data structures and such. All this code is far too time consuming to leave in a shipping version.
I understand why the Assert's in GPC are done that way, but it does not work for me in the way I use assertions.
I agree that it's useful to assert quite much (though I'm often too lazy to do so myself ...).
But I don't really understand the difference you make between turned off and compiled out. If assertions are turned off, no code is generated for them, unless they have side-effects, i.e. cases such as:
{ Returns True on success, False on failure. } function Foo (a: Integer): Boolean; [...]
Assert (Foo (42));
With assertions turned off, this is equivalent to:
Dummy := Foo (42);
(where Dummy is an otherwise unused Boolean variable).
This behaviour may be debatable. I think it would be more risky to discard side-effects as well (especially if most testing is done with assertions turned on).
But I'm not sure if that's actually what you're referring to.
Frank