Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

F2003 Unlimited polymorphic pointer question

butette
Beginner
835 Views
I am trying to use unlimited polymorphic pointer to point to different derived ttype depending on some select criteria but just can't seem to get it to work with ifort 11.1. I boils it down to the following simple example

!--------------------- example up.F90 ----------------------------

module junk_mod
type, public :: junk
integer :: ijunk
end type junk
type, extends(junk), public :: junke
real :: rjunk=-1234.0
end type junke
end module junk_mod

!-----------------

program test

use junk_mod
type(junk), target :: junk1
type(junke), target :: junk1e
class(*), pointer :: junkup

!-----------------

junkup => junk1e

select type (junkup)
type is (junk)
print *, 'junkup: ', junkup%ijunk
type is (junke)
print *, 'junkup: ', junkup%ijunk, junkup%rjunk
end select

! This subroutine call does not work,
! although it looks like it is the same as the select section above
call uptest(junkup)

!-----------------

junkup => junk1

select type (junkup)
type is (junk)
print *, 'junkup: ', junkup%ijunk
type is (junke)
print *, 'junkup: ', junkup%ijunk, junkup%rjunk
end select

! This subroutine call does not work,
! although it looks like it is the same as the select section above
call uptest(junkup)

end program test

!-----------------

subroutine uptest(this)
use junk_mod
class(*), pointer :: this

select type (this)
type is (junk)
print *, 'junkup: ', this%ijunk
type is (junke)
print *, 'junkup: ', this%ijunk, this%rjunk
class default
print *, 'unknown type'
end select

end subroutine uptest


-----------------------------------------

as far as I can tell the inline code segment should be the same as what is in subroutine uptest, and yet when I run
with the uptest call, I would get a SIGSEGV, while the inline code would do the right thing.

Am I misunderstanding the usage of unlimited polymorphic pointer, or is thisa bug in the compiler ?

Thanks.
b.
0 Kudos
5 Replies
Ben_Lauwens
Beginner
835 Views
Hello

The example compiles and runs without problems with ifort 11.1/072 when putting the subroutine in the main program:

program test
...
contains
subroutine uptest(this)
...
end subroutine uptest
end program test

I think an explicit interface is needed when the argument is a pointer.
I hope my answer is useful.

Ben
0 Kudos
butette
Beginner
835 Views
Hi Ben,

Thanks for the reply. Yes, I know that if you make it an internal subroutine (using contains) it will work because that is like having the code segment in place explicitly. While I don't see anywhere that says that I need an explicit interface for an external subroutine if I want to pass a pointer, but that looks like it is the problem. Well, at least I tried it and it seems to work.

I will go read the language definition again to see what I was missing.
I am telling you, F2003 rules are too complicated.

Thanks again!
Butette
0 Kudos
Steven_L_Intel1
Employee
835 Views
An explicit interface is needed when a dummy argument is either a pointer or is polymorphic.

If you compile with the "-warn interface" option the compiler will complain:

t.f90(32): warning #8055: The procedure has a dummy argument that has the ALLOCATABLE, ASYNCHRONOUS, OPTIONAL, POINTER, TARGET, VALUE or VOLATILE attribute. Required explicit interface is missing from original source. [JUNKUP]
call uptest(junkup)
------------^
t.f90(47): warning #8055: The procedure has a dummy argument that has the ALLOCATABLE, ASYNCHRONOUS, OPTIONAL, POINTER, TARGET, VALUE or VOLATILE attribute. Required explicit interface is missing from original source. [JUNKUP]
call uptest(junkup)
------------^
0 Kudos
butette
Beginner
835 Views
Thank you Steve... I guess I have not noticed that requirement in my normal usage before through module procedure with polymorphic argument, but I have never try to use it with an UP pointer before.
0 Kudos
Steven_L_Intel1
Employee
835 Views
You might also read my old article Doctor Fortran Gets Explicit, though this was written for F95. In general, I recommend using explicit interfaces everywhere, ideally by putting your procedures in modules. Failing that, use "-warn interface". I have noted and reported, though, that this doesn't warn for a missing interface when you have a polymorphic dummy argument that isn't a pointer.
0 Kudos
Reply