This is a question I raised on the list nearly 5 years ago that relates
to Interp 125. At the time compilers were all over the place on this
issue, so I wound up taking a different approach that was reliable.
Now, I'd like to get a definite yea or nay answer (if possible :-).
I want to write an accessor to an allocatable array component of a
derived type (with private components). What I have in mind is
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? Interp 125 says that if the dummy arg has the TARGET
attribute but the actual arg does not, then any pointers associated
with the dummy argument become undefined when execution of the
procedure completes. Unfortunately the text and examples of the
interp seem aimed squarely at subroutine procedures, and its not
clear to me how these apply to a pointer function. When exactly
has a function "completed execution"? I would say after its
results have been used, so that X gets aliased properly before the
result pointer X_PTR(B) becomes undefined, but I've not much
confidence in that assertion.
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.
Any thoughts?
Thanks! Neil
PS: Sorry for raising the spectre of another long interp 125 thread!
--
Neil N. Carlson Motorola, Los Alamos Research Park
Motorola Labs / PSRL 4200 W. Jemez Road, Suite 300
Computational Nanoscience Group Los Alamos, New Mexico 87544
[log in to unmask] Fax: (505) 663-5150
Voice: (505) 663-5106 Pager: [log in to unmask] or
888-946-2817
|