Inconsistency in ASSOCIATED Inquiry function

Inconsistency in ASSOCIATED Inquiry function

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

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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

Leave a Comment

Please sign in to add a comment. Not a member? Join today