Neil Carlson wrote:
> What value should the ASSOCIATED instrinsic return?
> Indeed, is it illegal to pass an expression as the second argument to
> set_bar_ptr (even when the result of that expression is a pointer)?
It certainly is legal to pass the expression there, since the argument
is INTENT(IN). In fact, changes are being made to the language to allow
a reference to a pointer-returning function to be used as an actual
even for an INTENT(OUT) dummy (however a recent interp decided this is
not legal at present (right?)).
What you are asking is whether it is OK for the compiler to make a copy
of the actual in the context you have quoted. This is a thorny issue,
and basically the standard says that if both the dummy and the actual
have the target attribute, and it is possible not to make a copy
(sometimes a copy is a must, such as when contiguity is required and
the actual is a section), a copy *must not* be made and pointer
associations must be preserved accross calls. This is all near the end
of section 12.4.1.2 in the F2003 (pseudo)standard.
That said, I believe the answer to your question is that ASSOCIATED must
return .TRUE. However, I cannot readily prove this from the standard.
The problem is that our standard as is has a problem of sometimes
talking about the actual argument, and sometimes about the thing that
the dummy is associated with (which in your case is the TARGET of the
pointer used as an actual argument). Section 12.4.1.2 seems to say "if
the actual has the TARGET attribute". The target of a pointer always
has that attribute, but the actual is an expression, and as such does
not have the TARGET attribute.
But I would not put it past the vendor to dispute this. If an interp is
filed I am relatively confident J3 will say that your example is legal
and a copy should not have been made. But this takes time...
Good luck,
Aleksandar
|