Print

Print


On Tue, Jul 25, 2017 at 9:56 PM, Malcolm Cohen <[log in to unmask]> wrote:
>..
>
> But there are NO processors which implement SAME_TYPE_AS as distinguishing between kinds for all types (as SELECT TYPE does).  Not a single one.  That is because the standard requires them not to distinguish between kinds for derived types.
>..

Separately I am taken aback by above statements, both as a matter of
accuracy (in a couple of ways of looking at them) and the consequent
relevance.

Is it not first that the standard with its sentence, "If neither A nor
B has extensible dynamic type, the result is processor dependent."
leave it up to the processor to decide whether to return true of false
as the result of the inquiry?  Which would be quite a bit different
from saying, "standard requires them not to distinguish between kinds
for derived types".

Also, "there are NO processors which implement SAME_TYPE_AS as
distinguishing between kinds for all types" - really?  Intel Fortran
seems to distinguish between kinds in every type I can conceive.  You
have already seen the earlier example involving REAL types (which
readers can check out with other intrinsic types), now see another one
with derived types below.  Can someone point out some kinds of types
that Intel Fortran fails to distinguish?

------- begin test code --------
   implicit none

   type :: foo(k)
      integer, kind :: k
   end type

   type, bind(C) :: bar
   end type

   type :: foobar
      sequence
   end type

   blk1: block
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( foo(k=1) :: x )
      allocate( foo(k=1) :: y )
      print *, "block 1"
      print *, "same_type_as(foo(k=1) :: x, foo(k=1) :: y) = ",
same_type_as(x,y)
      print *, "expected output is T", new_line("")
   end block blk1

   blk2: block
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( foo(k=1) :: x )
      allocate( foo(k=2) :: y )
      print *, "block 2"
      print *, "same_type_as(foo(k=1) :: x, foo(k=2) :: y) = ",
same_type_as(x,y)
      print *, "expected output is F", new_line("")
   end block blk2

   blk3: block
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( bar :: x )
      allocate( bar :: y )
      print *, "block 3"
      print *, "same_type_as(bar :: x, bar :: y) = ", same_type_as(x,y)
      print *, "expected output is T", new_line("")
   end block blk3

   blk4: block
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( foobar :: x )
      allocate( foobar :: y )
      print *, "block 4"
      print *, "same_type_as(foobar :: x, foobar :: y) = ", same_type_as(x,y)
      print *, "expected output is T", new_line("")
   end block blk4

   blk5: block
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( bar :: x )
      allocate( foobar :: y )
      print *, "block 5"
      print *, "same_type_as(bar :: x, foobar :: y) = ", same_type_as(x,y)
      print *, "expected output is F", new_line("")
   end block blk5

   blk6: block
      use, intrinsic :: iso_c_binding, only : c_ptr
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( c_ptr :: x )
      allocate( c_ptr :: y )
      print *, "block 6"
      print *, "same_type_as(c_ptr :: x, c_ptr :: y) = ", same_type_as(x,y)
      print *, "expected output is T", new_line("")
   end block blk6

   blk7: block
      use, intrinsic :: iso_c_binding, only : c_ptr
      class(*), allocatable :: x
      class(*), allocatable :: y
      allocate( c_ptr :: x )
      allocate( bar :: y )
      print *, "block 7"
      print *, "same_type_as(c_ptr :: x, bar :: y) = ", same_type_as(x,y)
      print *, "expected output is F", new_line("")
   end block blk7

end
------- end test code --------

Upon execution, the program gives

-------- begin output -----------
 block 1
 same_type_as(foo(k=1) :: x, foo(k=1) :: y) =  T
 expected output is T

 block 2
 same_type_as(foo(k=1) :: x, foo(k=2) :: y) =  F
 expected output is F

 block 3
 same_type_as(bar :: x, bar :: y) =  T
 expected output is T

 block 4
 same_type_as(foobar :: x, foobar :: y) =  T
 expected output is T

 block 5
 same_type_as(bar :: x, foobar :: y) =  F
 expected output is F

 block 6
 same_type_as(c_ptr :: x, c_ptr :: y) =  T
 expected output is T

 block 7
 same_type_as(c_ptr :: x, bar :: y) =  F
 expected output is F
-------- end output -----------

Thanks,
Vipul Parekh