Path: utzoo!attcan!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.c Subject: Out of range pointers Message-ID: <33432@cca.CCA.COM> Date: 17 Sep 88 22:54:21 GMT References: <867@osupyr.mast.ohio-state.edu> <3200@geac.UUCP> <1430@ficc.uu.net> <1988Sep15.145026.20325@ateng.uucp> <16041@ism780c.isc.com> <8515@smoke.ARPA> Reply-To: g-rh@XAIT.Xerox.COM (Richard Harter) Organization: Xerox Corporation, Cambridge, Massachusetts Lines: 34 In article <8515@smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: Re comments about x[-1] should be legal and should be in the standard. >I doubt that any effect on the computer industry would have occurred >other than reduced adherence to the postulated C standard. People >writing portable applications would still not be able to compute >&array[-1], since several compilers would ignore that requirement >(benchmark speed is a far greater driving factor than the desires of >a few sloppy programmers to compute non-existent addresses). What >good would that situation accomplish? Better that the standard be >widely followed and that programmers become better educated about >actual portability considerations, than to encourage false hopes for >availability of features that are difficult or detrimental to provide. You may be right about reduced adherence, at least in this regard. However the problem is not simply a matter of "sloppy" programming. In C a pointer is a fairly anonymous object. What you are saying is that it is a potential error to add or subtract an integer from a pointer if the result is out of range. Very well, but what is that range? Suppose a pointer is passed through a calling sequence. In the function I have no way of knowing whether &x[n] will break for any n other than 0. For that matter I have no way of knowing whether x is a legal pointer! In principle this is not right -- there is no way to write defensive code to check on pointer validity. To be sure a "correct" program never has an invalid pointer and all that but what about the rest of us poor mortals? -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.