Path: utzoo!attcan!uunet!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.fortran Subject: Re: Should I convert FORTRAN code to C? Message-ID: <12292@mimsy.UUCP> Date: 2 Jul 88 21:21:23 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <20518@beta.lanl.gov> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 59 >In article <2130@pt.cs.cmu.edu> jgk@speech2.cs.cmu.edu (Joe Keane) writes: >>Whether an array is static or dynamic has nothing to do with whether >>it contains arrays or pointers. (Joe is correct. A C array is simply `array N of T', where T is any valid C type except `function returning T1', and where N is constant. The last is the bugaboo.) In article <20518@beta.lanl.gov> jlg@beta.lanl.gov (Jim Giles) writes: >You haven't been reading this discussion at all! The C gurus all have been >saying that a static multidimensional array is implemented as pointer to >array, but that a dynamic multidimensional array is implemented as pointer >to pointer (to pointer ... etc for the number of dimensions). Only the false gurus. :-) More seriously, what C lacks in array handling is only the ability to conveniently write the following FORTRAN declaration: SUBROUTINE FOO(M, N, ARR) INTEGER M, N INTEGER ARR(M, N) ... ref ARR(i, j) ... END Ideally, one should be able to say void foo(int m, int n, int arr[n][m]) { ... /* ref arr[j][i] */ ... } /* called as foo(M, N, arr) */ and have both compilers do the same thing---namely, compute the address (&arr[0][0] + j * m + i). In practise, one must write void foo(int m, int n, int *arr) { ... /* ref arr[j*m + i] */ ... } /* called as foo(M, N, &arr[0][0]) */ There is at least one C compiler that supports the former syntax as an extension, namely the GNU compiler `gcc'. (It is a trivial extension, mechanically speaking, in most compilers.) >... The Fortran generally runs faster because its >conception of array is better suited to these types of optimization. which is correct, but not because of the form of subscripting, but rather because of an implicit rule against aliasing---a rule that I have seen violated in FORTRAN programs, incidentally. (Such programs are allowed to quietly produce mysterious results [as are malformed C programs that are equally easy to come by: different error, same lack of obviousness]. Ever hear someone gripe `but it works on VAX/VMS; the compiler must be broken'?) -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris