Contiguous Arrays
Andrew Koenig
ark at alice.UUCP
Tue Feb 21 23:38:39 AEST 1989
In article <2508 at ssc-vax.UUCP>, dmg at ssc-vax.UUCP (David Geary) writes:
>
> Are ALL arrays in C contiguious? If I declare an array:
>
> int x[10];
>
> am I GUARANTEED that x[0] through x[9] will occupy contiguous memory,
> or is the compiler free to scatter the elements around in memory?
You are guaranteed that if you say
int *p;
p = &x[k]; /* 0 <= k < 9 */
p++;
then p now points to x[k+1]. It is possible to execute `p++' in
a separately compiled routine.
For that reason it's hard to see how a C implementation could possibly
do anything but put x in contiguous memory.
--
--Andrew Koenig
ark at europa.att.com
More information about the Comp.lang.c
mailing list