Path: utzoo!attcan!uunet!lll-winken!ames!oliveb!apple!bloom-beacon!mit-eddie!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Contiguous Arrays Message-ID: <8966@alice.UUCP> Date: 25 Feb 89 17:26:00 GMT References: <2508@ssc-vax.UUCP> <8943@alice.UUCP> <1828@valhalla.ee.rochester.edu> <7309@killer.DALLAS.TX.US> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 25 In article <7309@killer.DALLAS.TX.US>, chasm@killer.DALLAS.TX.US (Charles Marslett) writes: > > There is no guarantee that there is a way to represent &space[0] - 101 > > at all. Further, computing it may cause overflows such that > > > > (&space[0] - 101) + 101 != &space[0] > > Please explain? What machine does this, or what architecture would allow > the machine or programming language to do it? The easiest case is if I give you a strictly checking C implementation in which evaluating &space[0]-101 causes your program to terminate with an error diagnostic. For such reasons, C is explicit about what addresses can validly be generated. If A is an array with n elements, then &a[0], &a[1], ... &a[n-1] are all valid addresses and can be used freely. Moreover, &a[n] can be generated and used for arithmetic and comparisons, provided that no attempt is ever made to examine or change the value of a[n]. A program that attempts to generate the address of any other `element' of A is an invalid C program and the implementation is permitted to do as it pleases with it. -- --Andrew Koenig ark@europa.att.com