Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!uakari.primate.wisc.edu!samsung!uunet!spool.mu.edu!cs.umn.edu!uc!shamash!paul From: paul@u02.svl.cdc.com (Paul Kohlmiller) Newsgroups: comp.lang.c Subject: Re: is this array access portable? Message-ID: <34591@shamash.cdc.com> Date: 27 Jun 91 20:22:51 GMT References: <1991Jun23.185351.5695@thunder.mcrcim.mcgill.edu> <1991Jun25.135920.4120@cs.odu.edu> <1991Jun26.160046.3404@gtephx.UUCP> Sender: usenet@shamash.cdc.com Lines: 30 baligag@gtephx.UUCP (Ganesh Baliga) writes: >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 ? I don't think you will see the words "row major" in the ANSI standard but then I also don't think you will see multidimensional arrays either. C has arrays of arrays but not multidimensional arrays. This distinction answers your question. The item a[0][1] follows a[0][0] because the array a[0] must be filled up before preceeding with array[1]. Did I explain that well enough? I don't know of any C compilers that do not use row major order because it would violate this C notion of arrays of arrays. On the other hand, I do know of Fortran compilers that can switch between row major and column major arrays. BTW, earlier in this thread someone said that arrays fill contiguous space but there is a catch in there. The X3J11 committee said the overindexing arrays to get to another part of the array is not guaranteed to work. For example; int a[4][4]; /* Is a[0][4] the same memory location as a[1][0] ? */ The committee said that it is not necessarily so but it is one of those arguments that involves a compiler noone uses. (Assuming I wrote it down right.) Paul Kohlmiller -- // Paul H. Kohlmiller // "Cybers, Macs and Mips" // // Control Data Corporation // Internet: paul@robin.svl.cdc.com // // All comments are strictly // America Online: Paul CDC // // my own. // Compuserve: 71170,2064 //