Xref: utzoo comp.lang.fortran:724 comp.lang.c:10632
Path: utzoo!attcan!uunet!husc6!necntc!ima!haddock!karl
From: karl@haddock.ISC.COM (Karl Heuer)
Newsgroups: comp.lang.fortran,comp.lang.c
Subject: Re: Should I convert FORTRAN code to C?
Summary: Multidimensional arrays
Message-ID: <4501@haddock.ISC.COM>
Date: 10 Jun 88 18:43:17 GMT
References: <10655@agate.BERKELEY.EDU> <1857@hubcap.UUCP> <10023@ames.arc.nasa.gov> <10032@ames.arc.nasa.gov>
Reply-To: karl@haddock.ima.isc.com (Karl Heuer)
Organization: Interactive Systems, Boston
Lines: 23

I really don't want to continue this cross-posted discussion, but I'd like to
comment on the multi-dimensional array issues.

In article <10032@ames.arc.nasa.gov> mwette%gauss@hub.ucsb.edu (Matt Wette) writes:
>Multidimensioned arrays in C are hard to implement well and in a way that
>will be portable.

Since we're talking about FORTRAN conversion, the straightforward solution is
to use the array notation supplied by the C language: "float a[3][5]".  The
only major problem is that FORTRAN allows an array parameter to be declared
with a nonconstant dimension; to render the equivalent code in C (unless you
have Gnu's gcc) requires explicit subscript calculation.  (This is no less
efficient than in FORTRAN, but it is tedious to write.  A macro can be
helpful.)

>Fortran code is _often_ optimized to account for Fortran's columnwise storage
>of 2-D arrays.  Pascal (and Ada, I assume) store rowwise.

No problem.  You translate the FORTRAN expression A(J,I) into the C expression
a[i][j], or its Pascal or Ada equivalent.  (This is assuming your translator
knows which parens are arrays rather than function calls.)

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint