the code
program asd
real,pointer :: a,b,c
allocate(a)
a=2.0
b=>a
c=>a
deallocate(b) !
print *, associated(c,target=a) ! T
end program
return T with intel compiler. I conclude that “b” is not a full alias of “a”, since I can not deallocate “a” taking “b”.
So my question is: if I construct a pointer with
function ptr
real,pointer :: var,ptr
allocate(var)
ptr=>var
end function
It is possible to deallocate var after to call this function?
Thank a lot-
The standard says (section 6.3.3.2):
Further on, in section 16.4.2.1, it says:
and in note 16.3 it points out that:
All of that is to say that the result of
.TRUE.from Intel you are getting is compiler-specific becausechas an undefined association status, which compilers can report any way they want. If you tried to accessathroughc, you would get a memory error (or even if it works, it is undefined and not a guarantee).Likewise, your example function is just as dangerous because there is no guarantee that
varwill exist when the function returns, meaning theptrfunction result is again undefined. So again, if you tried to accessvarthrough the result ofptr, you would again get a memory error.If you want your function to work, it would need to look like:
Of course, this begs the ultimate question — why
ALLOCATEpointers? It’s much safer to useALLOCATABLEfor the target and give it theTARGETattribute.