Xref: utzoo comp.lang.fortran:795 comp.lang.c:10860
Path: utzoo!attcan!uunet!husc6!bloom-beacon!mit-eddie!ll-xn!ames!ncar!noao!arizona!naucse!rrr
From: rrr@naucse.UUCP (Bob Rose )
Newsgroups: comp.lang.fortran,comp.lang.c
Subject: Re: Variable dimensioning in fortran (now in C)
Summary: close but no . . .
Keywords: language conversions, FORTRAN, c
Message-ID: <749@naucse.UUCP>
Date: 22 Jun 88 16:53:11 GMT
References: <2742@utastro.UUCP> <20008@beta.UUCP> <224@raunvis.UUCP> <517@philmds.UUCP>
Organization: Northern Arizona University, Flagstaff, AZ
Lines: 37

In article <517@philmds.UUCP>, leo@philmds.UUCP (Leo de Wit) writes:
> I'll repeat that code here for clearness (and removed the errors;
> this one will work 8-):
> 
> double **Create2DArray(w,h)
> int w,h;
> {
>     double **r, *a;
> 
>     a = (double *)calloc(w * h, sizeof(double));
>     r = (double **)calloc(h,sizeof(double *));
>     for ( ; --h >= 0; r[h] = a + w * h) ;
>     return r;
> }

Close, but ...  I assume you are using calloc to zero the array, but
the whole world is not a VAX. Try:

double **Create2DArray(w,h)
register int w,h;
{
    register double **r, *a, **q;
    register int i;

    if (((a = (double *)malloc(i = w*h, sizeof(double))) == 0) ||
        ((r = (double **)malloc(h,sizeof(double *))) == 0))
            abort();
    /*
     * Zero the array.
     */
    for (*r = a; i--; *a++ = 0.0) ;
    for (q = r, a = *r; --h; *++q = (a += w)) ;
    return r;
}

Just fuel for the fire.
                            -bob