Xref: utzoo comp.lang.fortran:783 comp.lang.c:10820 Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!noao!arizona!naucse!rrr From: rrr@naucse.UUCP (Bob Rose ) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Re: Should I convert FORTRAN code to C? Keywords: language conversions, FORTRAN, c Message-ID: <741@naucse.UUCP> Date: 20 Jun 88 22:04:49 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <29697@cca.CCA.COM> Organization: Northern Arizona University, Flagstaff, AZ Lines: 53 In article <29697@cca.CCA.COM>, g-rh@cca.CCA.COM (Richard Harter) writes: > In article <738@naucse.UUCP> rrr@naucse.UUCP (Bob Rose ) writes: > >Ok, what gives. Some else post the following code (not exact but close enough) > > [Some fortran code and the C equivalent] > > Yes, it does. However in fortran you can do the following > > real a(10) > ... > call foo(a,2,5) > call foo(a,5,2) > ... > subroutine foo(a,m,n) > real a(m,n) > ... > > This is what fortran users mean when they talk about variable dimensioning; > all it really means is that the compiler will generate address calculations > for arrays using variables as well as constants. You can do this by hand, > but it is much more convenient if the compiler will do it for you. As far > as I know, there is no good reason why this feature could not be added to > C. The discussion revolves around ways to fake it in C, using preprocessor > tricks. They all look kludgy to me. ^^^^^^ Here is the equivalent C code (right?) double a[10] ... foo(a,2,5) foo(a,5,2) ... #undef a void foo(a,m,n) double a[] #define a(x,y) a[(x)*n+(y)] /* works with ansi-c */ int m,n; { ... a(p,q) = ... /* same syntax as fortran, golly gee */ Yes, it is kludgy, but it does work. Sooo, the question again is is there any fortran constructs that cannot be translated into fortran through a brute force kludge. You know, something that a well trained ape couldn't do. I would like to see it. Please no complex numbers, these well just be function call (and if you are worried about speed, get a compiler that well do inline function calls.) -bob -