At 12:59 PM +0800 25/6/03, 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.
Caveat: I haven't used assert in GPC - too busy on the day job... - so maybe I'm barking up the wrong tree...
I agree being able to strip out assert code makes them much more powerful.
In my C code I (try to!) do precisely what you do, using my own onEntry, onExit and assert macros. These macros can strip the code out later, so as you're saying you're encouraged to use them to the nth degree. All of this ties in with traces for automated testing, etc. Nice to see another fan of this sort of thing :-)
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.
Enjoy, Peter.