Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!sharkey!atanasoff!hascall From: hascall@atanasoff.cs.iastate.edu (John Hascall) Newsgroups: comp.lang.c Subject: Re: Contiguous Arrays Message-ID: <830@atanasoff.cs.iastate.edu> Date: 22 Feb 89 03:07:47 GMT References: <2508@ssc-vax.UUCP> <8943@alice.UUCP> Reply-To: hascall@atanasoff.cs.iastate.edu (John Hascall) Organization: Iowa State U. Computer Science Department, Ames, IA Lines: 39 In article <8943@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: >In article <2508@ssc-vax.UUCP>, dmg@ssc-vax.UUCP (David Geary) writes: >> Are ALL arrays in C contiguious? If I declare an array:... >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. How about: Assume int's are (say) 2 bytes. Assume further that your machine is stupid, and all accesses must be on an 8-byte boundary. Suppose x[0] ends up at 0x01000, then x[1] ends up at 0x01008, and x[2] 0x01010, etc.... address (0x01000 base): 0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 ... x[?] 0 0 1 1 2 2 A non-contiguous array, and the compiler can always generate p <- p + 8 for p++; since it knows about the 8-byte alignment business. Or have I forgotten something? John Hascall / ISU Comp Center