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

ambiguous generic procedure?

clabra
Nouveau contributeur I
900 Visites
Hi!
I'm testing some modification in my code and I found a problem with the generic interface definitions. In the next sample, the compiler consider ambigous the definition of the procedure, but are different types!
If someone can help me with this, or explain me what is wrong here, please.

[cpp]module types
  implicit none
  private

  type t1_t
    real(8) :: a
  end type
 
  type t2_t
    integer :: a
  end type

  interface new
    module procedure new_t1, new_t2
  end interface

  public:: t1_t, t2_t, new

contains

  function new_t1()
    type(t1_t), pointer :: new_t1
    allocate(new_t1)
  end function
 
  function new_t2()
    type(t2_t), pointer :: new_t2
    allocate(new_t2)
  end function

end module types

program test

  use types
  implicit none

  type(t1_t), pointer :: t1
  type(t2_t), pointer :: t2

  t1 => new()
  t2 => new()

end program test[/cpp]

I understand that the compiler should recognize each procedure, or not?

thanks!
0 Compliments
3 Réponses
Steven_L_Intel1
Employé
900 Visites
Generic functions are distinguished by their arguments: new_t1 and new_t2 have no arguments. Generic resolution isn't done by function result type.
0 Compliments
clabra
Nouveau contributeur I
900 Visites
Generic functions are distinguished by their arguments: new_t1 and new_t2 have no arguments. Generic resolution isn't done by function result type.

Ok, thanks Steve.
I will change the function to subroutine.
Maybe in the future can be possible to verify the result type in functions...
0 Compliments
Steven_L_Intel1
Employé
900 Visites
If by that you mean the language will allow function result types to participate in generic resolution, that won't happen as there's nothing available to base the selection on. Fortran does not "look at" what is on the left side of an assignment when deciding on the meaning of the right side.
0 Compliments
Répondre