Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!hc!pprg.unm.edu!unmvax!tut.cis.ohio-state.edu!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c Subject: Re: Contiguous Arrays Message-ID: <8943@alice.UUCP> Date: 21 Feb 89 13:38:39 GMT References: <2508@ssc-vax.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 24 In article <2508@ssc-vax.UUCP>, dmg@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@europa.att.com