association of pointers



In an attempt to understand pointers, I wrote the following:

PROGRAM testassoc3
INTEGER, TARGET :: beast = 666
INTEGER, POINTER :: ptr => NULL()
ALLOCATE(ptr)
ptr = beast
PRINT "(A,I4)",' After ptr = beast, ptr is',ptr
PRINT "(A,L2)",' associated(ptr,beast) is',associated(ptr,beast)
PRINT "(A,L2)",' associated(ptr) is',associated(ptr)
END PROGRAM testassoc3

The output from four different f95 compilers was

After ptr = beast, ptr is 666
associated(ptr,beast) is F
associated(ptr) is T

That appears to suggest that ptr was associated with something at the
time of printing, but not with beast even though its value was that
of beast. What was ptr associated with?

-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@xxxxxxxxx phone (+64)(4)463 5341 fax (+64)(4)463 5045
.



Relevant Pages

  • Re: association of pointers
    ... INTEGER, TARGET:: beast = 666 ... PRINT "",' After ptr = beast, ptr is',ptr ... target are distinct entities; their association is temporary. ... anonymous target and then to associate the pointer with that target. ...
    (comp.lang.fortran)
  • Re: association of pointers
    ... INTEGER, TARGET:: beast = 666 ... PRINT "",' After ptr = beast, ptr is',ptr ... END PROGRAM testassoc3 ... -- John Harper, School of Mathematics, Statistics and Computer Science, Victoria University, PO Box 600, Wellington 6140, New Zealand ...
    (comp.lang.fortran)
  • Re: association of pointers
    ... John Harper wrote: ... INTEGER, TARGET:: beast = 666 ... That appears to suggest that ptr was associated with something at the time of printing, but not with beast even though its value was that of beast. ...
    (comp.lang.fortran)
  • Re: association with zero-length array?
    ... Requirements for pointer and target association ... POINTER attribute, TARGET attribute, pointer association ... If PTR has the POINTER attribute and TGT has the TARGET or ... and TGT considered to be pointer associated, i.e., under which of the ...
    (comp.lang.fortran)