select type and pointer assignment
- From: Hossein <talebi.hossein@xxxxxxxxx>
- Date: Sun, 19 Aug 2012 07:35:34 -0700 (PDT)
Hi All,
This piece of code below does not compile with INTEL compiler if I remove target from the statement:
class(POINT),allocatable ,target::pc_alloc
if I try to do "p3d_poi=>AN".
However, Gfrotran does not complain about pc_alloc not being a target. Ok, so the question is which one is standard Fortran? To me, "AN" is already a pointer so no need to be target.
Thanks and Cheers!
module mymod
type POINT
real :: X, Y
contains
procedure :: s1 => sub1
end type POINT
type, extends(POINT) :: POINT_3D
real :: Z
end type POINT_3D
type, extends(POINT) :: COLOR_POINT
integer :: COLOR
end type COLOR_POINT
contains
subroutine sub1(this)
class(POINT) :: this
end subroutine sub1
end module mymod
!================================================
program hello
use mymod
implicit none
type(POINT), target :: P
type(POINT_3D), target :: P3D
type(COLOR_POINT), target :: CP
class(POINT), pointer :: P_OR_CP
class(POINT),allocatable ,target::pc_alloc
class(POINT_3D),pointer ::p3d_poi
P_OR_CP=> CP
allocate (POINT_3D :: pc_alloc)
pc_alloc%X=1.
pc_alloc%Y=2.
select type ( AN => pc_alloc )
class is ( POINT )
! "class ( POINT ) :: AN" is implied here
print *, AN%X, AN%Y ! This block gets executed
type is ( POINT_3D )
! "type ( POINT_3D ) :: AN" is implied here
AN%Z=3.
p3d_poi=>AN
end select
print *, p3d_poi%X, p3d_poi%Y, p3d_poi%Z
end program
.
- Follow-Ups:
- Re: select type and pointer assignment
- From: Richard Maine
- Re: select type and pointer assignment
- Prev by Date: Re: substrings and array sections
- Next by Date: Re: select type and pointer assignment
- Previous by thread: substrings and array sections
- Next by thread: Re: select type and pointer assignment
- Index(es):