Contiguous Arrays
Andrew Koenig
ark at alice.UUCP
Sun Feb 26 03:26:00 AEST 1989
In article <7309 at killer.DALLAS.TX.US>, chasm at 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 at europa.att.com
More information about the Comp.lang.c
mailing list