multidimensional arrays in C
Chris Torek
chris at umcp-cs.UUCP
Mon Jan 7 04:55:45 AEST 1985
I would like to point out (or perhaps belabour the obvious) that
FORTRAN can't access multidimensional arrays without knowing the
dimensions either. If you write
SUBROUTINE FOO (A, N)
INTEGER N
REAL A(N,N)
INTEGER I, J
REAL V
...
V = A(I,J)
END
then the compiler computes the array as (pseudo C)
v = *(a + (j-1)*n + i-1); /* N.B.: this is NOT optimized */
(assuming I haven't screwed up my row & column order, as usual).
It takes JUST AS MUCH MACHINE TIME (though more programmer time*) to
access "ordinary" multi-dimensional arrays in C as it does in FORTRAN.
(And don't talk to me about your fancy optimizing compiler which
generates pointers to vectors; I can do that in C too. :-))
----------------
*This IS a consideration---but how much programmer time is wasted
finding bugs like DO 10 I = 1.20?
--
(This line accidently left nonblank.)
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (301) 454-7690
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at maryland
More information about the Comp.lang.c
mailing list