Ted Stern writes:
> >>>>> Aleksandar Donev writes:
> Aleksandar> Is the PRESENT statement in the following code legal?
>
> Aleksandar> subroutine test(x,...)
> Aleksandar> integer, optional, intent(in) :: x
> Aleksandar> ...
> Aleksandar> contains
> Aleksandar> subroutine internal(...)
> Aleksandar> ...
> Aleksandar> IF(PRESENT(x)) ... ! ??? x is not an argument of internal
> Aleksandar> end subroutine internal
> Aleksandar> ...
> Aleksandar> end subroutine test
>
> Anything not declared in the internal routine is inherited from the routine
> that CONTAINS it. So yes, it looks legal to me. You would actually get into
> more trouble if you passed x as an argument!
I emphatically disagree that you would get in trouble by passing x as
an argument. Overriding of host-associated names is well-defined. It
would be perfectly standard-conforming.
I'm not so sure about the legality of it as it stands. I was going to
say that it is illegal because x isn't a dummy argument of the current
scope. Just because x is inherited, that doesn't necessarily mean
that you could do PRESENT(x). I'd have guessed it to be illegal...
but on checking I don't see support for that guess in the f95
standard. Looking further... Hmm. F90 and f95 look distinctly
different here. I bet there was an interp that changed this.
The original f90 says in regard to the argument of PRESENT.
"A must be an optional argument of the procedure in which the
PRESENT function reference appears."
I'd interpret that as meaning that the code is illegal, since the
procedure in which the reference appears is the internal procedure,
which doesn't have X as a dummy argument.
But f95 says
"A shall be the name of an optional dummy argument that is
accessible in the subprogram in which the PRESENT function
reference appears."
To my reading, that is very different from what the original f90
said. This says to me that the code is legal.
Tracking down when it changed...Ok. Found it. This change was made
in corridendum 1 to f90 (which means it is officially part of f90).
This was f90 interpretation number 120. That interp has an example
and question almost identical to yours. The discussion of the interp says
"As long as the optional dummy argument is accessible it can be used
as an argument to the PRESENT intrinsic. An edit is provided for
clarification."
--
Richard Maine | Good judgement comes from experience;
[log in to unmask] | experience comes from bad judgement.
| -- Mark Twain
|