program dog
  use, intrinsic ::  iso_c_binding, only : c_ptr, c_int64_t, c_null_ptr,       &
                                           c_loc, c_f_pointer

  type :: array_t
    integer, dimension(:), pointer :: array
  end type array_t

  type, bind(c) :: rank1_t
    integer(c_int64_t) :: cnt=0
    type(c_ptr)        :: ptr=c_null_ptr
    type(c_ptr)        :: fptr=c_null_ptr
  end type rank1_t

  type(array_t),         pointer :: fptr
  integer, dimension(:), pointer :: array
  type(rank1_t)                  :: rank1
  integer, dimension(:), pointer :: temp
  type(array_t),         pointer :: tptr
  integer                        :: stat=0

continue
  rank1%cnt = 100
  allocate(array(rank1%cnt))
  rank1%ptr = c_loc(array)
  allocate(fptr)
  fptr%array => array
  rank1%fptr = c_loc(fptr)

  call c_f_pointer(rank1%fptr,tptr)
  deallocate(tptr%array, stat=stat)
  write(*,*) "Status:",stat
  deallocate(tptr, stat=stat)
  write(*,*) "Status:",stat
end program dog
