On Mon, 15 Jan 2001, Rhonda Frances Bailey wrote:

> hi all!
> 
> we have a program:
> 
> 
>       /* Prototypes */
>       void GJFullPivotInvert(int rank, const double **ar, double **target);
>       void PrintMatrixD(int rank, double **ar);
> 
>       #include<stdio.h>
>       int main(void)
>       {
>               double A[3][3] = {{1.0,2.0,3.0},{4.0,5.0,6.0},{7.0,8.0,9.0}};
>               double inverse[3][3];
> 
>               GJFullPivotInvertD(rank, A, inverse);
>               PrintMatrixD(3, inverse);
> 
>               return(0);
>       }
> 
> 
> inverse will be initialized in GJFullPivotInvertD.
> 
> gcc complains about the call to PrintMatrix, but not about the call to
> GJFullPivotInvertD().  here is the error:
> 
> example.c: In function `main':
> example.c:32: warning: passing arg 2 of `PrintMatrixD' from incompatible pointer type
> 
> can anyone shed light on this seeming inconsistency?

Very strange.  Both calls are invalid.  I don't know why one succeeds.

The memory allocated for variable "inverse" is 9 consecutive doubles.
The type of "inverse" is an array of arrays, which C can interpret as
a pointer to an array. Upon dereferencing that pointer, you do not
find another pointer located in that memory!  Thus, using "**" is invalid
in both calls.

To use this approach, you would have to try something like:

 double **inverse;
 int i;

 if ( NULL == ( inverse = (double **) calloc( 3, sizeof(double *) ))) exit( 1 );
 for ( i = 0 ; i < 3 ; i++ ) {
    if ( NULL == ( inverse[ i ] = calloc( 3, sizeof( double ) ) ) ) break;
 }
 if ( NULL == inverse[ 2 ] ) {  /* not all columns allocated */
    for ( i = 1 ; i >= 0 ; --i )
        if ( NULL != inverse[ i ] ) free( inverse[ i ];
    free( inverse );
    exit( 1 );
 }
 /* inverse successfully allocated */

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[EMAIL PROTECTED]>        Basics: ##.#.       ##.#.  Live Go...
Work:<[EMAIL PROTECTED]>              Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------

Reply via email to