Xref: utzoo comp.lang.fortran:774 comp.lang.c:10782 Path: utzoo!attcan!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Variable dimensioning in fortran Keywords: language conversions, FORTRAN, c Message-ID: <29605@cca.CCA.COM> Date: 17 Jun 88 19:57:23 GMT References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <3415@ut-emx.UUCP> <5917@aw.sei.cmu.edu> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 37 In article <5917@aw.sei.cmu.edu> firth@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.