In some Fortran 95 code, I have a type with a pointer field. I want to declare a module variable of type(foo) which is initialized at compile-time. Something like this:
module foo_module
implicit none
type foo_type
integer :: x
logical, pointer :: x_flag => null()
end type foo_type
logical, target :: bar_flag
! this does not compile of course:
type(foo_type) :: bar = foo_type(1, bar_flag)
end module foo_module
The snippet above does not compile. I understand that I can initialize bar at run time using a separate subroutine, like:
module foo_module
implicit none
type foo_type
integer :: x
logical, pointer :: x_flag => null()
end type foo_type
logical, target :: bar_flag
type(foo_type) :: bar
contains
subroutine init()
bar%x = 1
bar%x_flag => bar_flag
end subroutine init
end module foo_module
But is it possible to do this without an initialization subroutine? Or is it possible to declare an initialization subroutine which is called explicitly by the compiler? Note: this must be done in Fortran 95.