Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

associated problem

Blane_J_
New Contributor I
100 Views
program main
    implicit none

    type :: t
        integer :: a
    end type t

    type(t), pointer :: tp
    integer, pointer :: i

    if(associated(tp)) write(*,*) "tp is associated."
    if(associated(i )) write(*,*) "i  is associated."

end program main

Code above outputs a strange result of "i is associated" but tp is not, why is that ?

Intel(R) Visual Fortran Compiler 17.0.0.109 [IA-32] is the current compiler, and I also tried Linux version of ifort 13.1.1 and nothing wrong appears, thanks for reply.

0 Kudos
1 Solution
Arjen_Markus
Valued Contributor III
100 Views

The associated-ness of uninitialised pointer variables is undefined. So it could actually be true or false depending on the phase of the moon.

To be sure you have reliable results, always initialise them first, for instance:

type(t), pointer :: tp => null()

View solution in original post

2 Replies
Arjen_Markus
Valued Contributor III
101 Views

The associated-ness of uninitialised pointer variables is undefined. So it could actually be true or false depending on the phase of the moon.

To be sure you have reliable results, always initialise them first, for instance:

type(t), pointer :: tp => null()

View solution in original post

Blane_J_
New Contributor I
100 Views

That's interesting about the moon :)

Reply