Re: Passing a 2 dimensional array from fortran to c++
- From: Rich Townsend <rhdt@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 29 Jun 2005 20:24:16 -0400
glen herrmannsfeldt wrote:
> Sam wrote:
>
>> Hello all
>> I have a two dimensional array (the dimensions are not known)
>
>> that needs to be passed to fortran from c++.
>
>> Say in my c++ code I have;
>
>
>> extern "C" { void foo_(float **, int &, int &); }
>
>
>> int main()
>> {
>> ...........
>> .............
>> int rows, columns;
>> float **array2d; // Now i need to pass this to the fortran code, the
>> allocation of the array and
>> // and filling it is done in the fortran code.
>> // How do i pass this to the fortran subroutine now, i did it this way
>
>
>> foo_(array2d, rows, columns);
>
>
>> // One more question, do i need to do the allocation and
>
>> // stuff here again
>
>> // Do some stuff to manipulate with the array2d
>
>
> (snip)
>
>> subroutine foo(arr,rows,columns)
>> integer rows, columns
>> real*8 ,allocatable:: arr (:,:)
>> ! do some stuff to allocate the arrray and fil the stuff
>
>
> First (float**) is not a two dimensional array. It is a pointer to
> pointer to float. It is often used in place of 2D arrays, but it still
> isn't one. Some will even say that a C array declared like:
>
> float x[10][10];
>
> isn't a 2D array, either, but I will disagree.
>
How so? Surey, x[10] has type (float *)? I thought that in C,
x[i]
is purely syntactic sugar for *(x+i). Am I wrong?
cheers,
Rich
.
- Follow-Ups:
- Re: Passing a 2 dimensional array from fortran to c++
- From: glen herrmannsfeldt
- Re: Passing a 2 dimensional array from fortran to c++
- References:
- Passing a 2 dimensional array from fortran to c++
- From: Sam
- Re: Passing a 2 dimensional array from fortran to c++
- From: glen herrmannsfeldt
- Passing a 2 dimensional array from fortran to c++
- Prev by Date: Re: Passing a 2 dimensional array from fortran to c++
- Next by Date: Re: Passing a 2 dimensional array from fortran to c++
- Previous by thread: Re: Passing a 2 dimensional array from fortran to c++
- Next by thread: Re: Passing a 2 dimensional array from fortran to c++
- Index(es):
Relevant Pages
|