Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

More Polymorphic Pointers - Upcasting

$
0
0

Hello there once again,

I have been playing with some upcasting (and downcasting) with Fortran's polymorphism these days, but I am not really sure about what is allowed.

I am basically creating a derived type ExtList_T which extends List_T. The pointers are downcast and then upcast again - or return a nullpointer in case it is not possible to upcast. The part of interest is:

TYPE(ExtList_T), POINTER  :: instance1
TYPE(ExtList_T), POINTER  :: instance2
CLASS(ExtList_T), POINTER  :: ptr_ext
CLASS(List_T), POINTER  :: ptr_lst

(...)

ptr_ext => Cast_ExtList(instance1%last())

PRINT *,"Worked? ",ASSOCIATED(ptr_ext)

ptr_lst => instance1%last()
ptr_ext => Cast_ExtList(ptr_lst)

PRINT *,"Worked? ",ASSOCIATED(ptr_ext)

I expected it to print "Worked?   T" in both occasions, but only the second one gets printed properly with Intel Fortran. gfortran prints the expected result in both cases.

The sample code follows attached.
Thanks in advance for your attention!

AttachmentSize
Downloadapplication/octet-streammini.f901.16 KB
Downloadapplication/octet-streamminimain.f90740 bytes

Viewing all articles
Browse latest Browse all 3270

Trending Articles



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