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

Inconsistency in ASSOCIATED Inquiry function

gmclaren
Beginner
220 Views
In CVF 6.6B why does the following program produce the output: T F?

program TEST
implicit none
type sp
real (8) , pointer :: x(:,:)
end type sp
logical l1,l2
type (sp)::xx
type (sp),allocatable::yy(:)
allocate (yy(1))
l1=associated(xx%x)
l2=associated(yy(1)%x)
print *,l1,l2
pause
end program TEST
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
220 Views
Because pointers can have three states: associated, nullified and undefined -- I bet you forgot about the last one. All pointers start their life as undefined (unless explicitly initialized); it is illegal even to query ASSOCIATED on an undefined pointer, and the results are, as you discovered, unpredictable.

I got the habit to always apply F95 default-initialization to derived types:
type sp
   real (8) , pointer :: x(:,:) =>NULL()
end type sp
That should fix it.

Jugoslav
0 Kudos
Reply