Should I convert FORTRAN code to C?

Bob Rose rrr at naucse.UUCP
Tue Jun 21 08:04:49 AEST 1988


In article <29697 at cca.CCA.COM>, g-rh at cca.CCA.COM (Richard Harter) writes:
> In article <738 at naucse.UUCP> rrr at 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


-



More information about the Comp.lang.c mailing list