These are chat archives for Fortran-FOSS-Programmers/General-Discussion

25th
May 2017
Jacob Williams
@jacobwilliams
May 25 2017 14:59
Neil Carlson
@nncarlson
May 25 2017 17:12
@jacobwilliams Actually the trick of boxing the polymorphic pointer also allows you to preserve the metadata associated with the polymorphic variable. An example:
Neil Carlson
@nncarlson
May 25 2017 17:23
program main

  use iso_c_binding

  type box
    class(*), pointer :: p => null()
  end type
  type(box), target  :: pbox
  type(box), pointer :: qbox
  type(c_ptr) :: cp

  allocate(pbox%p, source=1)
  cp = c_loc(pbox)
  call c_f_pointer(cp, qbox)

  select type (q => qbox%p)
  type is (integer)
    print *, 'got integer', q
  class default
    print *, 'lost dynamic type'
  end select

end program