Is &a[NTHINGS] legal

David Collier-Brown daveb at geac.UUCP
Thu May 5 22:45:20 AEST 1988


In article <1450 at iscuva.ISCS.COM> carlp at iscuva.ISCS.COM (Carl Paukstis) writes:
>The above notion follows from a quick reading of Mr. Gwyn's original
>followup.  It seems, however, that there need not be an addressable OBJECT
>beyond the array bound, and it is an error to attempt to dereference
>a[NTHINGS+1].  There must be a valid ADDRESS (or at least simulation of
>one), so that size calculations will work, mostly, but also so that
>bound-checking as proposed in the original posting is possible.

  My understanding is that one has to be able to generate the
address of the last-plus-one'th element of an array:
	thing a[NTHINGS];
	...

	if (x < &a[NTHINGS]) ...

  I'm not so sure about NTHINGS+1, which is the last-plus-two'th
(last-plus-tooth?) element.

  As you might expect, this reqirement identifies a problem with
machines like the DPS-6, which will need the shim at &a[NTHINGS] to
keep from trapping when the address is loaded into a register and
checked for legality.

 --dave
-- 
 David Collier-Brown.                 {mnetor yunexus utgpu}!geac!daveb
 Geac Computers International Inc.,   |  Computer Science loses its
 350 Steelcase Road,Markham, Ontario, |  memory (if not its mind) 
 CANADA, L3R 1B3 (416) 475-0525 x3279 |  every 6 months.



More information about the Comp.lang.c mailing list