Manual Reference Pages  - same_type_as (3fortran)

NAME

SAME_TYPE_AS(3) - [STATE:INQUIRY] Query dynamic types for equality

SYNOPSIS

result = same_type_as(a, b)

         logical same_type_as(a, b)

type(TYPE(kind=KIND)),intent(in) :: a type(TYPE(kind=KIND)),intent(in) :: b

CHARACTERISTICS

o A shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.
o B shall be an object of extensible declared type or unlimited polymorphic. If it is a polymorphic pointer, it shall not have an undefined association status.

DESCRIPTION

SAME_TYPE_AS(3) queries the dynamic types of objects for equality.

OPTIONS

o A : object to compare to B for equality of type
o B : object to be compared to for equality of type

RESULT

If the dynamic type of A or B is extensible, the result is true if and only if the dynamic type of A is the same as the dynamic type of B. If neither A nor B has extensible dynamic type, the result is processor dependent.

    NOTE1

The dynamic type of a disassociated pointer or unallocated allocatable variable is its declared type. An unlimited polymorphic entity has no declared type.

    NOTE2

The test performed by SAME_TYPE_AS is not the same as the test performed by the type guard TYPE IS. The test performed by SAME_TYPE_AS does not consider kind type parameters.

Sample program:

      ! program demo_same_type_as
      module M_ether
      implicit none
      private

type :: dot real :: x=0 real :: y=0 end type dot

type, extends(dot) :: point real :: z=0 end type point

type something_else end type something_else

public :: dot public :: point public :: something_else

end module M_ether

program demo_same_type_as use M_ether, only : dot, point, something_else implicit none type(dot) :: dad, mom type(point) :: me type(something_else) :: alien

write(*,*)same_type_as(me,dad),’I am descended from Dad, but equal?’ write(*,*)same_type_as(me,me) ,’I am what I am’ write(*,*)same_type_as(dad,mom) ,’what a pair!’

write(*,*)same_type_as(dad,me),’no paradox here’ write(*,*)same_type_as(dad,alien),’no relation’

call pointers() contains subroutine pointers() ! Given the declarations and assignments type t1 real c end type type, extends(t1) :: t2 end type class(t1), pointer :: p, q, r allocate (p, q) allocate (t2 :: r) ! the result of SAME_TYPE_AS (P, Q) will be true, and the result ! of SAME_TYPE_AS (P, R) will be false. write(*,*)’(P,Q)’,same_type_as(p,q),"mind your P’s and Q’s" write(*,*)’(P,R)’,same_type_as(p,r) end subroutine pointers

end program demo_same_type_as

Results:

        F I am descended from Dad, but equal?
        T I am what I am
        T what a pair!
        F no paradox here
        F no relation
        (P,Q) T mind your P’s and Q’s
        (P,R) F

STANDARD

Fortran 2003

SEE ALSO

EXTENDS_TYPE_OF(3)

fortran-lang intrinsic descriptions


Nemo Release 3.1 same_type_as (3fortran) April 28, 2024
Generated by manServer 1.08 from 32059d51-9f7e-42e4-8cc3-bdc93e12427f using man macros.