Re: Passing a 2 dimensional array from fortran to c++



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
.



Relevant Pages

  • Re: allocating memory for array of pointers to char
    ... >> checking up on allocation and so on, the types of your objects are ... > pointer inside a linked-list element. ... > typedef struct listelem_t { ... "value" is a pointer to an array of unknown length. ...
    (comp.lang.c)
  • Re: Newbie on the lose.. How to add an unknown length dataset to an array
    ... allocation, it does require enough virtual memory to hold twice the ... consisting of one of these records plus a pointer. ... Having read all the data into the list, I know the size of the array ... and your pointer method makes good sense from since it dosen't ...
    (comp.lang.fortran)
  • Re: Ancient history
    ... If a pointer holds origin, ... > segment of memory wholly contained within a single allocation ... > into one allocation into a pointer into another. ... dimensional array to a subroutine with a one dimensional dummy argument. ...
    (sci.crypt)
  • Re: allocating space for Node**
    ... you should avoid this style of allocation. ... >my image is pointed to by "source" pointer, to allocate space for the table i ... CArray is a bit clumsy for 2D arrays because there's a problem with assignment ... Given you haven't constructed the array elements, ...
    (microsoft.public.vc.mfc)
  • Re: Newbie on the lose.. How to add an unknown length dataset to an array
    ... allocation than with the reallocation approach. ... when I'm reading data of unknown size into an array, ... consisting of one of these records plus a pointer. ...
    (comp.lang.fortran)