Quantcast
Channel: Intel® Software - Intel® Fortran Compiler for Linux* and macOS*
Viewing all articles
Browse latest Browse all 2746

problem with allocatable character variable inside a polymorphic linked list

$
0
0

Hello. I noticed this problem with an allocatable character variable when used inside a polymorphic linked list compiled with  ifort version 13.0.1  . The output is the following. 

First output: allocatable character

D

D

D

D

Second output: assigned length character

A

B

C

D

What am I doing wrong?

 program main
 implicit none
 type :: linked_list
 class(linked_list), pointer :: prev
 class(linked_list), pointer :: next
 class(*), pointer :: data
 end type
 type :: named_type_A
 character(:),allocatable :: name
 end type
 type :: named_type_B
 character(len=1) :: name
 end type
 type(named_type_A),target :: t_a
 type(named_type_B),target :: t_b
 class(*),pointer :: polydata
 class(linked_list),pointer :: listA, listB
 character(len=1),dimension(4) :: ch
 integer :: i_list
 ch=(/'A', 'B', 'C ', 'D'/)
 ! FIRST OUTPUT CORRECT 
 print*, 'First output: allocatable character'
 polydata=>t_a
 allocate(listA)
 do i_list = 1, 4
 t_a%name=ch(i_list)
 allocate(listA%data,source=polydata)
 allocate(listA%next)
 listA%next%prev=>listA
 listA=>listA%next
 end do
 do while(associated(listA%prev))
 listA=>listA%prev
 end do
 do i_list = 1, 4
 select type(q=>listA%data)
 type is(named_type_A)
 print*, q%name
 end select 
 listA=>listA%next
 end do
 print*, 'Second output: assigned length character' 
 polydata=>t_b
 allocate(listb)
 do i_list = 1, 4
 t_b%name=ch(i_list)
 allocate(listb%data,source=polydata)
 allocate(listb%next)
 listb%next%prev=>listb
 listb=>listb%next
 end do
 do while(associated(listB%prev))
 listB=>listB%prev
 end do
 do i_list = 1, 4
 select type(q=>listB%data)
 type is(named_type_B)
 print*, q%name
 end select 
 listB=>listB%next
 end do
 end program

Viewing all articles
Browse latest Browse all 2746

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>