Variable dimensioning in fortran

Richard Harter g-rh at cca.CCA.COM
Sat Jun 18 05:57:23 AEST 1988


In article <5917 at aw.sei.cmu.edu> firth at bd.sei.cmu.edu.UUCP (Robert Firth) writes:

>The following code, contributed by a C programmer, allocates dynamic
>memory for a two-dimensional array:

>>                                 For this particuliar
>> data structure, the subroutine is basically a one-liner:

>> double **Create2DArray(w,h)
>> int w,h;{ double **r;
>> for(r=(double**)calloc(h,sizeof(*r));h-->0;r[h]=(double*)calloc(w,sizeof(**r)));
>> return(r);}

>Any Fortran programmer who seriously proposes to convert to C would, in
>my opinion, be advised to study this example very carefully.  Verbum
>sapienta sufficit.

	This little trick is all very well, but it does not reproduce the
fortran facility for variable dimensioning, and it does matter.  The above
yields an array of arrays.  Consider the following:

	real a(2,5)
	call foo(a)
	....
	subroutine foo(a)
	real a(10)
	...

In this example a is originally allocated as an array of 10 contiguous
locations; subroutine foo takes advantage of that knowledge.  The point
of fortran subscripting rules is that the dimension structure can be
changed dynamically.
-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list