The following question is a constructor of a Fortran type constructor defined using the C function , I approached this inoperative example with gfortran 4.9:
module my_module
use iso_c_binding
type, bind(c) :: my_double
real(c_double) :: x
real(c_double) :: y
end type my_double
interface my_double
procedure my_module_fortran_new_my_double
end interface
interface
type(my_double) function my_module_fortran_new_my_double (v) bind ( c )
use iso_c_binding
import :: my_double
real (c_double), intent(in) :: v
end function my_module_fortran_new_my_double
end interface
end module my_module
program main
use my_module
type(my_double) x
x = my_double(12)
end program main
Following the previous question , a Fortran-derived type constructor defined using the C function , fixing the module works fine. However, the specified constructor is not recognized by my compiler.
Here is the compiler output:
$ gfortran -std=f2008 test.f90 -o test.o -c
test.f90:22.6:
x = my_double(12)
1
Error: No initializer for component 'y' given in the structure constructor at (1)!
It looks like my used constructor is not taken into account. Can someone help me understand what I did wrong (again)?
source
share