control the life of a C struct from fortran.

Tobias Burnus burnus@net-b.de
Thu Dec 18 15:47:00 GMT 2008


Hello,

cyril giraudon wrote:
> void person_alloc(person* p) { p = malloc(sizeof(person)); return; }
>
>    subroutine person_alloc(p) bind(c, name="person_alloc")
>      type(c_ptr), intent(out) :: p
I have not tried, but I think you need:

type(c_ptr), VALUE, intent(out) :: p

as you want to pass a C pointer and not a pointer (reference) to a C
pointer. (I admit that is a bit confusing for C pointers, but Fortran
passes the arguments by reference and not by value as C does.)

Tobias



More information about the Fortran mailing list