Converting FORTRAN to C

D Gary Grady dgary at ecsvax.UUCP
Thu Dec 20 01:13:26 AEST 1984


<>
There is a real problem in converting FORTRAN to C, because there is one
FORTRAN feature that is widely used and not duplicated in C:  the
ability to pass varying-sized arrays as parameters.  That is, the
following is not legal C, but the equivalent is legal FORTRAN:

C:				FORTRAN:

subr(array, size)		SUBROUTINE SUBR(ARRAY,ISIZE)
int size;			INTEGER ISIZE
float array[size][];		REAL ARRAY(1,ISIZE)
{ ...				...
}				RETURN
				END

(I don't believe C formally specifies the order of array elements, but
in practice the row-major form is used, I think.  FORTRAN, of course,
stores column-major.)

It is possible to pass variant-sized arrays in C by passing an array of
pointers to arrays, or by simulating a 2-dimensional array by means of a
one-dimensional one (handling the subscript computation with a #define
or a subroutine would be easiest here).  But I would like to see this
simple feature added to C; I doubt it would break any existing programs.

D Gary Grady, Duke University Computation Center (dgary at ecsvax)
{...!(ihnp4,decvax,etc)!mcnc!ecsvax!dgary}

-- 

D Gary Grady
Duke University Computation Center, Durham, NC  27706
(919) 684-4146
USENET:  {decvax,ihnp4,akgua,etc.}!mcnc!ecsvax!dgary



More information about the Comp.lang.c mailing list