title: Is it possible to use a pointer in type constructor in fortran?
body: <p>In some Fortran 95 code, I have a type with a pointer field. I want to declare a module variable of <code>type(foo)</code> which is initialized at compile-time. Something like this:</p>
  
  <pre><code>module foo_module
    implicit none
    type foo_type
       integer :: x
       logical, pointer :: x_flag =&gt; 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
  </code></pre>
  
  <p>The snippet above does not compile. I understand that I can initialize <code>bar</code> at run time using a separate subroutine, like:</p>
  
  <pre><code>module foo_module
    implicit none
    type foo_type
       integer :: x
       logical, pointer :: x_flag =&gt; null()
    end type foo_type
  
    logical, target :: bar_flag
    type(foo_type) :: bar
  contains
    subroutine init()
      bar%x = 1
      bar%x_flag =&gt; bar_flag
    end subroutine init
  end module foo_module
  </code></pre>
  
  <p>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.</p>