Generic Type Binding Procedures with Procedure Arguments

I am trying to write a generic type-bound procedure that performs various callback functions as parameters. When compiling the following code (with ifort 12.1.3), I get the following warning:

module test type :: a_type contains procedure :: t_s => at_s procedure :: t_d => at_d generic :: t => t_s,t_d end type a_type abstract interface integer function cb_s(arg) real(4) :: arg end function cb_s integer function cb_d(arg) real(8) :: arg end function cb_d end interface contains subroutine at_s(this,cb) class(a_type) :: this procedure(cb_s) :: cb end subroutine subroutine at_d(this,cb) class(a_type) :: this procedure(cb_d) :: cb end subroutine end module test 

A warning:

 compileme.f(27): warning #8449: The type/rank/keyword signature for this specific procedure matches another specific procedure that shares the same generic binding name. [AT_D] 

It seems that the compiler does not distinguish between different functional interfaces when using procedures as arguments ...

My question is: why are these types not checked and what is the correct, clean way to write generic procedures with a type binding with procedures or procedure pointers as arguments?

Possible Solution

As Vladimir F pointed out, only the return arguments to the callback function are checked by type. In my case, it is normal to slightly change the function interfaces:

 abstract interface real(4) function cb_s(arg) real(4) :: arg end function cb_s real(8) function cb_d(arg) real(8) :: arg end function cb_d end interface 
+4
source share
1 answer

The compiler is right because Fortran 2008 12.4.3.4.5 has restrictions on general announcements

Two dummy arguments differ if one is a procedure and the other is a data object — they are both data objects or that are known as functions, and neither of them is compatible with TKR with the other — each attribute has ALLOCATABLE, and the other has attribute POINTER or - one of them is a function with a nonzero rank, and the other, as you know, is not a function.

This means that both of your functions are entire functions, so they are not different.

+3
source

Source: https://habr.com/ru/post/1246991/


All Articles