Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!elroy.jpl.nasa.gov!lll-winken!xanth!cs.odu.edu!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.lang.c Subject: Re: is this array access portable? Message-ID: <1991Jun25.135920.4120@cs.odu.edu> Date: 25 Jun 91 13:59:20 GMT References: <1991Jun23.185351.5695@thunder.mcrcim.mcgill.edu> Sender: news@cs.odu.edu (News File Owner) Organization: Old Dominion University, Norfolk, VA Lines: 23 Nntp-Posting-Host: opium.cs.odu.edu 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