Trying to use polymorphism with the transfer intrinsic, I ran into a behaviour that I don't understand.
With the following test program, i get the following output :
storage req. size = 16
text = h!O�p!O��
If I replace "class default" with "class is (str)", I get the expected :
storage req. size = 16
text = hello !
Am I doing something wrong ?
Thanks !
Franck
module polymorphic character(len=1), private, dimension(:), allocatable :: storage type str character(len=16) :: text end type str contains subroutine store(arg) implicit none class(*), intent(in) :: arg integer :: i_size type(str) :: probe select type (arg) ! class is (str) class default i_size = size(transfer(arg,storage)) write (*,*) ' storage req. size = ',i_size allocate(storage(i_size)) storage = transfer(arg,storage) probe = transfer(storage, probe) write (*,*) 'text = ', probe%text end select end subroutine store end module polymorphic program test_polymorphic use polymorphic type(str) :: input input%text = 'hello !' call store(input) end program test_polymorphic