Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Out of range pointers Message-ID: <1988Oct1.220705.10625@utzoo.uucp> Organization: U of Toronto Zoology References: <867@osupyr.mast.ohio-state.edu> <3200@geac.UUCP> <1430@ficc.uu.net> <1988Sep15.145026.20325@ateng.uucp> <16041@ism780c.isc.com <28227@think.UUCP> <8557@smoke.ARPA> <33666@XAIT.XEROX.COM> <8564@smoke.ARPA> <33789@XAIT.XEROX.COM> <1988Sep27.172738.16453@ut <34041@XAIT.XEROX.COM> Date: Sat, 1 Oct 88 22:07:05 GMT In article <34041@XAIT.XEROX.COM> g-rh@XAIT.Xerox.COM (Richard Harter) writes: >>... in general one must draw the line somewhere. It's almost always >>possible to add just one more check. There usually has to be some sort of >>balance with efficiency. > > It is true that one always has to take into account the tradeoff >between efficiency and error checking. However that is not normally the >tradeoff involved in parameter validation. Unless the body of a function >is very short and very fast, parameter validation execution times are a >nominal part of the total cost of a function invocation. Ah, but it depends on how much validation you want to do, which was my point. I'm passing in a pointer to a complex data structure. Do I just check the pointer for being NULL? Do I confirm that the node it points at has a magic number in the right place? Do I inspect the rest of the node's data for plausibility? Do I apply the same tests to the node's neighbors? Do I apply a graph-tracing algorithm to verify correct linking of the whole multi-node structure? I've actually done all of these things at various times. It depends on the tradeoffs. (My normal practice? I almost always check for NULL, and usually have magic-number code controlled by #ifdef DEBUG. And any time my code vitally depends on some non-obvious property I'll usually throw in an assert(), partly to document the fact and partly as an error-catcher. The other things are responses to unusual situations.) -- The meek can have the Earth; | Henry Spencer at U of Toronto Zoology the rest of us have other plans.|uunet!attcan!utzoo!henry henry@zoo.toronto.edu