Checksum: 46256 Lines: 42 Path: utzoo!sq!msb From: msb@sq.uucp (Mark Brader) Date: Fri, 23-Sep-88 14:10:42 EDT Message-ID: <1988Sep23.141042.23951@sq.uucp> Newsgroups: comp.lang.c Subject: Re: Out of range pointers Summary: Man bites dog! Henry makes error! 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> <1988Sep19.213023.13181@utzoo.uucp> <33547@XAIT.XEROX.COM> <1988Sep21.163915.19848@utzoo.uucp> Reply-To: msb@sq.com (Mark Brader) Organization: SoftQuad Inc., Toronto The conclusion given is right; the reason is wrong. Richard Harter (g-rh@XAIT.Xerox.COM) writes: > >As a side note, one argument for making x[-1] legal is that it permits > >you to use sentinels in both directions. I don't see that this is a > >problem, regardless of architecture. All that is required is that nothing > >be allocated on a segment boundary... Henry Spencer (henry@utzoo.uucp), no less, replies: > The situation unfortunately isn't as symmetrical as it looks, because > a pointer to an array element points to the *beginning* of the array > element. He must not have gotten over his cold yet. The correct statement is: a pointer to an array element *is typically implemented as* pointing to the beginning of the array element. Depending on the machine architecture, it might be equally well implementable as a pointer to the *end* of the array element. Other implementations are also conceivable. A pointer to anything points to *all* of the thing, at once. The following code copies all of y over all of x, doesn't it? (Assuming that x and y have types for which the operations are legal.) p = &x; q = &y; *p = *q; I'm feeling rather sensitive about this point just now, because I've been discussing by email with David Prosser, the editor of the Draft ANSI Standard for C, the several errors in its descriptions of array and pointer operations. It appears that he and his predecessors made the same or similar mistakes. > Both practices have been technically illegal all along, > so legitimizing both wasn't vitally necessary. Since x[size] gets used > a lot and is cheap to do, it was legalized. Since x[-1] was rather more > costly and is used less, it wasn't. Rather, since x[size] gets used a lot and x[-1] is used less, *and an implementation is possible on most or all machines where x[size] is cheap*, it was appropriate to bless x[size]. Mark Brader "True excitement lies in doing 'sdb /unix /dev/kmem'" utzoo!sq!msb, msb@sq.com -- Pontus Hedman