Sunday 2 April 2001
> Date: Fri, 30 Mar 2001 18:52:04 -0500
> From: Ron Sverdlove x2517 <[log in to unmask]>
> The copy of the F95 standard that I have (not the final version) says
> in Section 14.7.6 "Events that cause variables to become undefined",
> paragraph (13a), that an "actual argument associated with a dummy
> argument with INTENT(OUT) becomes undefined" when the procedure is
> invoked.
>
> I tried the following simple program on the two compilers I have
> available (NAG and Sun).
>
> program intnt
> integer :: i
> i = 3
> call sub(i)
> print *,i
> stop
> contains
> subroutine sub(i)
> integer,intent(out) :: i
> integer :: ieof,j
> print *,'Enter i:'
> read(*,*,iostat=ieof) i
> j = 3
> return
> end subroutine sub
> end program intnt
>
> With both compilers, the main program printed out "3" for i when I
> entered an end-of-file in response to the read statment in the
> subroutine. It appears that although the INTENT(OUT) dummy argument
> became undefined, the corresponding actual argument retained its
> previous definition status.
That's right.
As soon as the procedure is called with argument "i", the
value of "i" becomes underfined. It remains undefined until
the procedure assigns a value to the dummy argument "i".
As the procedure never assigned a value to the dummy argument before
it returned control to the caller, the actual argument "i" in the calling
program remained undefined.
The value it originally had (viz. 3) was not altered in your cases (because no assignment
was made to the dummy argument), but it is still undefined nevertheless.
The compiler manufacturer is free to replace the value of the actual
argument with anything appropriate. Alternatively, the compiler mfr
may be free to trap the reference to the undefined variable.
> Is this a mistake in the compilers, or
> is it just the usual "when you refer to an undefined variable, the
> program becomes non-standard-conforming and so the compiler can do
> whatever it wants to."?
That's right.
> By the way, where in the standard does it
> explicitly say that you can't refer to an undefined data object?
> Ronald Sverdlove Visual Information Systems Research
|