is this array access portable?

Lloyd Kremer kremer at cs.odu.edu
Tue Jun 25 23:59:20 AEST 1991


In article <1991Jun23.185351.5695 at thunder.mcrcim.mcgill.edu> mouse at thunder.mcrcim.mcgill.edu (der Mouse) writes:
>
>	sometype foo[40][50];
>	sometype *fp;
>	int i;
>
>	fp = &foo[0][0];
>	for (i=2000;i>0;i--) *fp++ = something;
>
>Is this portable?  (The significant question is whether the wraparound
>from the end of one row to the beginning of the next is guaranteed to
>work correctly.)

Arrays are guaranteed contiguous, therefore arrays of arrays (being arrays
themselves) are guaranteed contiguous.

foo is an array of 40 contiguous objects each of which is an array of 50
contiguous sometypes.  So foo occupies exactly 40 * 50 * sizeof(sometype)
contiguous bytes of memory, the same as "sometype foo[2000]" would.

					Lloyd Kremer
					Hilton Systems, Inc.
					kremer at cs.odu.edu



More information about the Comp.lang.c mailing list