Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

select type bug ??

Patrice_l_
Beginner
3,091 Views

Hi all,

I put a small example together to show a behavior i don't understand, hoping for some explanation here. 

This code end up with the following in intel 15 version, the copy is not made despite the select type.  Also Is the extends_type_of results correct ?

Thanks.

class cm2 is type tm T
 class cm2 is class cm T
 class cm2 is type tc T
 class cm2 is class cc T
 cm2=cm          10           1

With gfortran 4.9.1 I have :

class cm2 is type tm T
 class cm2 is class cm T
 class cm2 is type tc F
 class cm2 is class cc T
 cm2=cm          10           1

 

program toto
implicit none

type mother
integer :: i
end type mother
type,extends(mother) :: child
end type child

type(mother) :: tm
type(child) :: tc
class(mother),allocatable :: cm,cm2
class(child),allocatable :: cc

 allocate(cm)
 allocate(child::cm2)
 cm%i=10
 cm2%i=1
 select type (cm2)
 type is (mother)
                cm2=cm
 end select
 print *,'class cm2 is type tm',extends_type_of(cm2,tm)
 print *,'class cm2 is class cm',extends_type_of(cm2,cm)
 print *,'class cm2 is type tc',extends_type_of(cm2,tc)
 print *,'class cm2 is class cc',extends_type_of(cm2,cc)
 print *,'cm2=cm', cm%i,cm2%i
 
end program

 

0 Kudos
23 Replies
Steven_L_Intel1
Employee
334 Views

You don't have to write an assignment routine if you're assigning the same type.

0 Kudos
FortranFan
Honored Contributor III
334 Views

Patrice l. wrote:

...

Avoiding select type i guess is just a matter of keeping the code simple, especially for nested select type (see other post). Also i feel that select type is just putting a lot of "if" for something that can be resolve at compile time.

...

My feeling is that having to write an assignment subroutine for a type, is like asking me to write "assembly code" to do real a =real b. :)

Thanks much for sharing your thoughts and code.  An important detail to include would have been how the arguments of copy_structc are defined, but I'll now sign off as the arguments are getting circular.  I've not experienced nor seen any evidence anywhere else of the concerns you have. Unless you've deep, deep, deep, deep nesting in your class design, I don't think any of the issues you raise are of real concern.  You may ask yourself if you are not trying to make things simpler than necessary which then can lead to higher complexity?   As I was reading, I was reminded of the quote attributed to Einstein (but possibly of unknown origin), "Everything should be made as simple as possible, but not simpler."  

0 Kudos
Patrice_l_
Beginner
334 Views

I am really not  trying to argue, and actually I want to learn from your experience with OO fortran as well. The copy is for class mother, define with two class(mother) .

0 Kudos
Reply