concerning:
...
>>subroutine zero (number, doit)
>> integer, intent(out) :: number
>> logical, intent(in) :: doit
>>
>> if (doit) then
>> number = 0
>> end if
>>end subroutine zero
Malcolm Cohen <[log in to unmask]> wrote:
>It certainly is free to do that - the actual argument associated with "number"
>becomes undefined on invocation of "zero". If you want to preserve the
>previous value you must use either INTENT(INOUT) or no INTENT.
and James Giles wrote:
! While this may be the correct interpretation of the wording of the standard
! (and that's not quite clear), it is hard to imagine a plausible
implementation
! which actually changes the value of an actual argument to some "undefined"
! value because the subroutine never defined it. Subroutines are supposed
! to be an abstraction mechanism. The above should not leave the actual
! argument associated with NUMBER undefined any more than explicitly writing
! the correponding IF block inline at the point of the procedure call would.
! That is to say, the actual argument is either defined by the procedure, or
! it retains the definition status it previously had (including its value,
! if any).
! At least, that's how the language should define it. If not, we've got a
! lurking trap for future programmers (assuming anyone ever builds an
! implementation which explicitly "undefines" INTENT(OUT) arguments that
! don't get assigned within the procedure).
The present definition allows copy-in / copy-out. In the case of INTENT(OUT),
it's just copy-out. The "number" argument of the procedure can be created
on the stack, without copy-in, and it's therefore initially undefined --
that is, junk on the stack. At the end, it can be copied out -- junk and all.
Retaining the previous status would require copy-in as well as copy-out.
The abstract semantics of INTENT(OUT) were intended to be the way they are.
Best regards,
Van Snyder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|