The bind
attribute can also be applied to derived types:
geese.h
struct Goose {
int flock;
float buoyancy;
}
struct Goose goose_c;
geese.f90
use, intrinsic :: iso_c_binding, only : c_int, c_float
type, bind(C) :: goose_t
integer(c_int) :: flock
real(c_float) :: buoyancy
end type goose_t
type(goose_t) :: goose_f
Data can now be transferred between goose_c
and goose_f
. C routines which take arguments of type Goose
can be called from Fortran with type(goose_t)
.