Newsgroups: comp.std.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: ANSI C, hardware protection, out-of-bounds pointers Message-ID: <1989Sep5.175411.25203@utzoo.uucp> Organization: U of Toronto Zoology References: <427@maytag.waterloo.edu> Date: Tue, 5 Sep 89 17:54:11 GMT In article <427@maytag.waterloo.edu> lhf@aries5 (Luiz H. deFigueiredo) writes: >ANSI C says that is *is* legal to use mention (but not dereference) a pointer >just out-of-bounds [on the high end]... >Now I ask, it is possible/legal to do the analogous thing for a-1 ... No. High-end out-of-bounds pointers are very common, and all an implementation usually has to do to make them work is to ensure that the end of the array is at least one byte below a segment boundary (assuming that the hardware has segments), so that a high-end pointer is still in the same linear address space as a normal one and address arithmetic therefore works as expected. Low-end out-of-bounds pointers are much less common, and making them work would typically require that the beginning of the array be at least one array-element-size after a segment boundary... which can get expensive if the elements are big. The asymmetry is because a pointer to an object generally points to its beginning. It was felt (I am told) that the cost:benefit ratio was favorable for high-end but not for low-end. So it is not legal or portable to do this for a-1. (Whether it is possible is implementation-dependent.) -- V7 /bin/mail source: 554 lines.| Henry Spencer at U of Toronto Zoology 1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry@zoo.toronto.edu