Neil Carlson wrote:
> function x_ptr (a) result (xptr)
> type(my_type), target, intent(in) :: a
> integer, pointer :: xptr(:)
> xptr => a % x
> end function x_ptr
>
>Then X=>X_PTR(B) would make X an alias for that component of B (well,
>that's what I'd like it to do). The question is, must B have the TARGET
>attribute?
>
Yes, it must. All interp 125 says (with much verbosity) is that if and
only if both the actual and the dummy have the TARGET attribute, there
will be no copy in/out when calling the procedure (be it subroutine or
function), and thus pointers associated with the dummy will indeed be
associated with the actual and vice versa. Your word tinkering about
functions and such doesn't seem relevant to me, and I would definitely
not rely on it in terms of what the compilers will do.
>If B must be a target in order for this to work, then I don't believe
>this is a viable approach for an accessor, as there would be no way
>to verify that the actual argument is declared properly. This is
>the ultimate issue I'm trying to resolve.
>
Yes, there is no way to verify that the actual is indeed a TARGET. In
some cases, Fortran requires an explicit interface for called procedures
that have such special arguments. I don't believe this is one of the
cases. The reason is (I think) that one may want to make a dummy TARGET
just so one can point pointers to it inside the procedure (but you
better not make it PURE :().
The whole "solution" of interp 125, and in general the TARGET attribute,
has some deficiencies, which makes this whole situation a mess. But
don't ask me how to fix it. For now, make sure your TARGET's are
everywhere :(
Aleksandar
|