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

associated unexpectedly returns false on pointer associated with derived type

jhaiducek
Beginner
826 Views
 

I have a program that associates a pointer to an instance of a derived type, then checks whether the pointer is associated with the intended object. When I compile the program with ifort (19.0.4.243), the associated() function returns false.

 

The program is as follows:

 

module mod_pointer_association

  type mytype
  end type mytype

contains

  subroutine test_association(obj)

    class(mytype), target, intent(in)::obj
    class(mytype), pointer::ptr

    ptr=>obj

    if (.not. associated(ptr)) then
       print *, "ptr not associated"
       error stop
    end if

    if (.not. associated(ptr, obj)) then
       print *, "ptr not associated with obj"
       error stop
    end if

  end subroutine test_association

end module mod_pointer_association

program test_pointer_association

  use mod_pointer_association

  type(mytype), target::myobj

  call test_association(myobj)

end program test_pointer_association

 

 
The program produces the following output when compiled with ifort 19.0.4.243:
 

 

$ ./test_pointer_association 
 ptr not associated with obj

 

 
Which suggests that either the => or the associated intrinsic function did not perform the function I expect it to, because the associated function returned False when called with the pointed-to variable as the target, immediately after using => to associate the pointer.
 
The same program produces no output (as expected) when compiled with gfortran 9.2.0.
0 Kudos
3 Replies
TobiasK
Moderator
752 Views

Hi @jhaiducek


can you please try to add something to your derived type?

If I add an integer for example, your program works as you expect. Is there a real use case where you want to have an empty derived type or is this just a toy example?


Best

Tobias


0 Kudos
TobiasK
Moderator
696 Views

Hi @jhaiducek

Has your issue been resolved? If I don't hear from you within 5 business days, I will assume your support request is resolved and you no longer need assistance


0 Kudos
TobiasK
Moderator
618 Views

Hi @jhaiducek

please open a new thread if you need further assistance. 

0 Kudos
Reply