Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!hrc!gtephx!baligag From: baligag@gtephx.UUCP (Ganesh Baliga) Newsgroups: comp.lang.c Subject: Re: is this array access portable? Summary: Array addressing schemes. Message-ID: <1991Jun26.160046.3404@gtephx.UUCP> Date: 26 Jun 91 16:00:46 GMT References: <1991Jun23.185351.5695@thunder.mcrcim.mcgill.edu> <1991Jun25.135920.4120@cs.odu.edu> Organization: AGCS Lines: 31 In article <1991Jun25.135920.4120@cs.odu.edu>, kremer@cs.odu.edu (Lloyd Kremer) writes: > In article <1991Jun23.185351.5695@thunder.mcrcim.mcgill.edu> mouse@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@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 ?