is this array access portable?

Paul Kohlmiller paul at u02.svl.cdc.com
Fri Jun 28 06:22:51 AEST 1991


baligag at 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 at robin.svl.cdc.com   //
     // All comments are strictly    // America Online: Paul CDC         //
     // my own.                      // Compuserve: 71170,2064           // 



More information about the Comp.lang.c mailing list