intent(out) arguments

beliavsky_at_aol.com
Date: 11/24/03


Date: 24 Nov 2003 08:12:00 -0800

If I call a procedure with an intent(out) argument, and the procedure
does not set the value of that argument, is the value of the argument
in the calling program defined?

For the following code,

module intent_mod
contains
subroutine foo(x)
real, intent(out) :: x
end subroutine foo
end module intent_mod

program xintent
use intent_mod
implicit none
real :: x
x = 4.0
call foo(x)
write (*,*) "x =",x
end program xintent

Digital Visual Fortran prints x = 4.0, but the output for LF95 5.00
depends on the compiler options used. I think it is safer for a
programmer to assume that an intent(out) argument not defined in a
subroutine is undefined when returned to the calling code. At the
beginning of subroutines, I often set the intent(out) arguments to
dummy values, so that they will have defined values even if
there is a premature exit from the subroutine.

I have come across several codes that assume that intent(out)
arguments, often error flags, keep their prior value from the calling
code when they are not set in the subroutine. These codes break when I
compile them with all of LF95's debugging options turned on.



Relevant Pages

  • Calling Intel Visual Fortran from Python
    ... I have been exploring calling Fortran DLL subroutines from Python. ... thing can be done on at the level of a subroutine, ...
    (comp.lang.fortran)
  • Re: Strange SYS$ENQ problem
    ... The process waiting for the lock to be released, ... I will try calling the subroutine from a different place within the ... Powerhouse program on Tuesday. ...
    (comp.os.vms)
  • Re: How to compile the example_itsol_1.f , and why always meets these errors.
    ... > the arguments are different at the calling point and where the subprogram ... > Subroutine my_sub ... it try to call the DITSOL_PCG which is a cxml ...
    (comp.lang.fortran)
  • Re: [9fans] Non-stack-based calling conventions
    ... All of them push parameters on the stack. ... Here's the calling convention for your entertainment. ... locations just past the call to the subroutine. ... the first word of the routine. ...
    (comp.os.plan9)
  • Re: segmentation fault
    ... while calling a subroutine. ... part where main program is calling the subroutine and the subroutine's ... User communities for Intel Software Development Products ... Intel Fortran Support ...
    (comp.lang.fortran)