Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran Generic Procedures

Lukas_W_
Beginner
448 Views

Good day,

compiler reports errors on line 12 (generic, public :: Set => Set_integer, Set_real):

  • Error    1     error #5082: Syntax error, found ',' when expecting one of: ( % : . = =>    D:\FEM\_FemPnLin\_pokusy\81 Fortran - Generic\generic\generic module.f90    12   
  • Error    2     error #5082: Syntax error, found '=>' when expecting one of: ( * ) :: , <END-OF-STATEMENT> ; + . - % (/ [ : ] /) . ** / // ...    D:\FEM\_FemPnLin\_pokusy\81 Fortran - Generic\generic\generic module.f90    12   

I use a the compiler v 11.1.067. I can not find what I'm doing wrong?
Thank you

[fortran]

module Generic_test_mod
  implicit none
  private
 
  type, public :: container
    integer(4), private :: i = 0
    real(8), private :: r = 0.
  contains
    private
    procedure :: Set_integer
    procedure :: Set_real
    generic, public :: Set => Set_integer, Set_real
  end type container
 
contains
 
  subroutine Set_integer(this, val)
    implicit none
    class(container), intent(in out) :: this
    integer(4), intent(in) :: val
    this%i = val
  end subroutine Set_integer
 
  subroutine Set_real(this, val)
    implicit none
    class(container), intent(in out) :: this
    real(8), intent(in) :: val
    this%r = val
  end subroutine Set_real
    
end module Generic_test_mod

[/fortran]

0 Kudos
1 Reply
Simon_Geard
New Contributor I
448 Views

I don't think you're doing anything wrong other than using an old compiler. I've tried your code in 13.1.0.149 and it compiles without error.

0 Kudos
Reply