is this array access portable?

Ganesh Baliga baligag at gtephx.UUCP
Thu Jun 27 02:00:46 AEST 1991


In article <1991Jun25.135920.4120 at cs.odu.edu>, kremer at cs.odu.edu (Lloyd Kremer) writes:
> 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
 

Is the row major addressing scheme part of the C language definition
or is it one of those unwritten rules for C compiler writers ? If
this varies over compilers, all hell could break loose.

Could someone please comment ?



More information about the Comp.lang.c mailing list