Richard Maine <[log in to unmask]> writes:
>Werner Schulz writes:
> > a) the pointer attribute is not used for distinguishing arguments
> > for resolving generic/overloaded procedure arguments, right?
>
>Correct. And it really couldn't be allowed to be distinguishing
>without causing various complications and incompatabilities. [...]
...
>If there were two specific procedures distinguished only by the
>pointerness of a dummy, it would be ambiguous whether a call with
>a pointer actual argument was intended to pass the target to the
>non-pointer dummy version or the pointer to the pointer dummy version.
You can get around this with a derived data type consisting only of a
pointer:
Type MY_PTR
Real, Pointer :: loc
End Type MY_PTR
...
Type(MY_PTR) :: x_ptr
Real :: x
...
x_ptr%loc => x
Then if your generic procedure had the interface:
interface foo
subroutine foo_a( x )
real :: x
end subroutine foo_a
subroutine foo_b( x )
Type(MY_PTR) :: x
end subroutine foo_b
end interface
The result would be that calls to foo with x asd x_ptr as arguments
would generate the separate calls. You probably already know this,
but anyone reading this thread with less complete knowledge of the
standard might have concluded that there was no way within Fortran
to do this at all. It's a little harder with the Fortran rule than it might
be, but I think pointers should be hard to use - it discourages them.
> > b)
> > If a dummy argument has the target attribute any actual argument does not
> > need the target attribute?
>
>I think you are right, but I always have trouble reading that part of
>the standard (and the various interpretations against it). So don't
>place much weight on my concurrence here. Better wait for an answer
>from someone that understands that part better.
The problem is that if Richard Maine doesn't know this, who does? :-)
However, I think this is correct. The result would have an undefined
status if you passed a pointer and a non-target variable to a procedure
(where the corresponding dummy *has* the target attribute) and the
procedure tried to return with the pointer referencing part or all of the
other argument. That use would violate the standard. But, if you don't
do that, and instead have the dummy argument used as a pointee just
within the called procedure, that would seem to be a reasonable use.
--
J. Giles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|