Silverfrost Forums

Welcome to our forums

Optional arguments

17 Jul 2020 2:51 #26029

The following code does not generate a runtime error using FTN95 or gfortran, but NAG issues a message at line 5 (the call to s2) indicating that there is a reference to optional argument r which is not present. I thought the NAG compiler was in error, but apparently it is correct because line 5 should be written as:

Call s2 (r=r)

to avoid a declaration that argument r is present.

Module m
Contains
 Subroutine s1 (r)
   Integer, Dimension(:), Optional :: r
    Call s2 (r=r(:))
   Return
 End Subroutine s1

 Subroutine s2 (r)
   Integer, Dimension(:), Optional :: r
   Return
 End Subroutine s2
End Module m

Program p
   Use m, Only: s1
   Implicit None
   Call s1 ()
End Program p
17 Jul 2020 3:05 #26030

Simon

A first sight I suspect that NAG is mistaken.

17 Jul 2020 5:00 #26032

Hi Paul.

That's what I thought too. They wrote back with the response:

With the array section in the call

Call s2 (r=r(:))

you are referencing r, which is not permitted in the Fortran standard if r is not present.

And then they suggested using

Call s2 (r=r)

I do not know what the standard is, but thought I would report this issue here in case a fix is needed and in case anybody else is experiencing similar issues.

Please login to reply.