Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Out of range pointers Message-ID: <1988Sep19.213023.13181@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> <8515@smoke.ARPA> <33432@cca.CCA.COM> Date: Mon, 19 Sep 88 21:30:23 GMT In article <33432@cca.CCA.COM> g-rh@XAIT.Xerox.COM (Richard Harter) writes: >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? The members of the array that the pointer points into, plus the special case of just above the end of the array. >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! That's correct. It is the caller's responsibility to supply a pointer that is adequate for the function's purposes, and the function writer's responsibility to document those purposes well enough that the caller knows what his responsibilities are. There is no way to check this at runtime in conventional C implementations. That's C for you. -- NASA is into artificial | Henry Spencer at U of Toronto Zoology stupidity. - Jerry Pournelle | uunet!attcan!utzoo!henry henry@zoo.toronto.edu