Should I convert FORTRAN code to C?

Karl Heuer karl at haddock.ISC.COM
Sat Jun 11 04:43:17 AEST 1988


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 at ames.arc.nasa.gov> mwette%gauss at 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 at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list