Quantcast
Channel: Intel® Fortran Compiler
Viewing all articles
Browse latest Browse all 3270

Compilation failure when passed-object argument follows absent optional argument

$
0
0
Module mytype_module
!Example taken from "Fortran 95/2003 explained," by Metcalf, Reid, Cohen, Page 280;

!IFORT 16.0.0 compilation fails with
!"error #6074: The number of actual arguments does not match the definition.   [WRITE]"
!when the passed-object argument follows an absent optional argument

!It seems to me that
!              call x%write
!is implemented as
!            call write_mytype(x),
!instead of
!          call write_mytype(this = x),
!which could explain the compilation failure

   Use iso_fortran_env, Only: output_unit
   Implicit None

   Type mytype
      Real :: myvalue(4) = 0
   Contains
      Procedure, Pass(this) :: write => write_mytype
   End Type mytype

   Private :: write_mytype
Contains

   Subroutine write_mytype(unit, this)
      Integer, Optional         :: unit
      Class(mytype), Intent(In) :: this

      If(Present(unit)) Then
         Write(unit, *) this%myvalue
      Else
         Print '(4f6.3)', this%myvalue
      End If
   End Subroutine write_mytype

End Module mytype_module

Program test
Use mytype_module
   Implicit None

   Type(mytype) :: x = mytype((/1, 2, 3, 4/))

                               !WAY to make IFORT compile:
   Call x%write                !comment out this line and
   !Call x%write(output_unit)  !uncomment this, so as to provide the
                               !optional argument

End Program test

 


Viewing all articles
Browse latest Browse all 3270

Trending Articles