Phillip,
At 02:07 08-04-2000 +0100, you wrote:
>> One of my compilers was perfectly happy to accept an optional dummy
>> argument as an I/O specifier, viz. "advance=adv", where "adv" was
>> an optional dummy argument.
>>
>> Furthermore, if the actual argument associated with "adv" was not
>> present, the run-time was perfectly happy to pretend I hadn't
>> specified "advance=".
>>
>> I found this to be rather elegant, but I suspect it isn't standard-
>> conforming behavior. The section on I/O statements is quite large,
>> however, so I'm not sure whether there's something therein that defines
>> specifier values or variables to behave like actual arguments associated
>> with optional dummy arguments, and I missed it, or there's nothing
>> there.
>
>PROGRAM TEST
interface ! needed here
end interface
>PRINT*, 'YES' ! works as expected
>CALL TEST_ADV("YES")
>PRINT*
>PRINT*, 'NO' ! works as expected
>CALL TEST_ADV("NO")
>PRINT*
>!PRINT*, 'NOTHING' ! causes access violation and crashes
! [JvO] The crash is most probbly caused by the absence of an actual address
! for the ADV dummy argument.
! A procedure with an optional argument needs an explicit interface.
! [/JvO] Without it the compiler warns for calls with different # of
arguments.
>!CALL TEST_ADV()
>!PRINT*
>!PRINT*, 'NOTHING' ! causes access violation and crashes
>!CALL TEST_ADV ! [JvO] Works same as above; () are not needed
for subroutine.
>!PRINT*
>!PRINT*, 'INVALID' ! gives "%FOR-F-INVARGFOR, invalid argument
> ! to FORTRAN Run-Time Library" and crashes
>!CALL TEST_ADV("VAN_SNYDER")
>END
>SUBROUTINE TEST_ADV(ADV)
>CHARACTER (LEN=*), OPTIONAL, INTENT(IN) :: ADV
> WRITE (*,'(T2,A)',ADVANCE=ADV) "first"
> WRITE (*,'(TR1,A)',ADVANCE="YES") "second"
>END
---
Meilleures Salutations,
Best Greetings,
/---
Jan van Oosterwijk
Computing Centre
Delft University of Technology
Postbus 354
2600 AJ Delft
Netherlands / Pays-Bas
Phone: +31 15 278 50 17
Fax: +31 15 278 37 87
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|