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

Procedure pointer in parameterized derived type

Stephan_S
Beginner
970 Views

The following code does not compile with ifort Version 2021.3.0 on MacOS:

module my_mod
implicit none

type my_type(rkind)
integer, kind :: rkind
real(kind=rkind) :: val
procedure(sub_interface), pointer, nopass :: sub => NULL()
end type my_type

abstract interface
subroutine sub_interface(x, y)
real(kind=8), intent(in) :: x
real(kind=8), intent(out) :: y
end subroutine sub_interface
end interface

contains

subroutine bla_my_type_8(m_in,m_out)
implicit none
type(my_type(8)), intent(out) :: m_out
type(my_type(8)), intent(in) :: m_in
! do something here, e.g.
m_out%val = 2*m_in%val
m_out%sub => m_in%sub
end subroutine bla_my_type_8

subroutine sqrt_sub(x, y)
implicit none
real(kind=8), intent(in) :: x
real(kind=8), intent(out) :: y
y = sqrt(x)
end subroutine sqrt_sub

end module my_mod

program my_prog
use my_mod
implicit none
type(my_type(8)) :: m
real(kind=8) :: x, y

x = 16
m%sub => sqrt_sub
call m%sub(x, y)
write(*,*) 'y =', y

end program my_prog

As an error message, I get:

prog.f90(44): error #8178: The procedure pointer and the procedure target must have matching arguments.

  m%sub => sqrt_sub

--^

prog.f90(45): error #6784: The number of actual arguments cannot be greater than the number of dummy arguments.   [SUB]

  call m%sub(x, y)

---------^

compilation aborted for prog.f90 (code 1)

Strangely, if I either remove the subroutine bla_my_type_8 *or* if I use a non-parameterized derived type, everything works as expected. 

It may be important to note explicitly here that the above code does not do anything useful. It is the result of me trying to isolate an error in a large project. I also know that the need to use a parameterized derived type (PDT) is not apparent from the example, but PDTs make a lot of sense in the original application this example was distilled from.

Labels (2)
0 Kudos
1 Solution
FortranFan
Honored Contributor II
948 Views

@Stephan_S ,

 

Per my understanding of the Fortran standard, the errors are due to issues with Intel compiler.  If you have support subscription, please submit a request at Intel OSC: https://supporttickets.intel.com/servicecenter?lang=en-US

Otherwise, you can hope Intel staff will pick up the incident from here.

View solution in original post

0 Kudos
3 Replies
FortranFan
Honored Contributor II
949 Views

@Stephan_S ,

 

Per my understanding of the Fortran standard, the errors are due to issues with Intel compiler.  If you have support subscription, please submit a request at Intel OSC: https://supporttickets.intel.com/servicecenter?lang=en-US

Otherwise, you can hope Intel staff will pick up the incident from here.

0 Kudos
Stephan_S
Beginner
937 Views

Thanks for the quick reply! I will check if we have support subscription and file a request if possible.  

0 Kudos
Devorah_H_Intel
Moderator
875 Views

Thank you for the report. This issue has been escalated to engineering. 

0 Kudos
Reply