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

Internal procedure as actual argument (error)

Ferdinand_T_
New Contributor II
1,684 Views

Dear readers, I am seeking you for advice on passing internal procedures as actual arguments, which is a fortran 2008 feature supported by ifort 15.0. The following module does not compile in ifort 15.0, because

error #7069: The characteristics of the associated actual function result
 differ from the characteristics of the dummy function result.   [NESTED]
		call with_dummy_function(nested)
-----------------------------------------^
compilation aborted for test.f90 (code 1)

Here is the code:

module m
	implicit none

	abstract interface
		function dummy_function()
			logical :: dummy_function
		end function
	end interface

contains

	subroutine host()
		call with_dummy_function(nested)
	contains
		function nested()
			logical :: nested
			nested = .true.
		end function
	end subroutine

	subroutine with_dummy_function(func)
		procedure(dummy_function), pointer, intent(in) :: func
	end subroutine
end module 

While I managed to compile and run the same code with ifort 14 (service packs .3 and .4 ), any tips on how to get this feature to work with ifort 15.0 are appreciated!

Best regards

Ferdinand

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,684 Views

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

View solution in original post

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,684 Views

The issue here is that you are passing an internal procedure to a procedure pointer. If the argument to with_dummy_function was just a procedure, not a procedure pointer, it works.  I had at first thought that it was not allowable to use an internal procedure in this context, but on research I find that it is. I will escalate this to the developers.

0 Kudos
Steven_L_Intel1
Employee
1,685 Views

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

0 Kudos
Ferdinand_T_
New Contributor II
1,684 Views

Thank you, Steve, for the prompt reply.

Indeed, dropping the pointer attribute

    subroutine with_dummy_function(func)
        !procedure(dummy_function), pointer, intent(in) :: func
        procedure(dummy_function) :: func
    end subroutine

does work fine.

 

 

0 Kudos
Ferdinand_T_
New Contributor II
1,684 Views

Steve Lionel (Intel) wrote:

Escalated as issue DPD200370165. A workaround is to create a procedure pointer, assign the pointer to the internal procedure and pass the pointer. As a note of information, you should be using "abstract interface" for dummy_function.

Thank you for the hint, I edited my code. I never fully understood where to use abstract - and where to use "normal" - interfaces. Probably I should always go with "abstract" in f2k code unless something breaks... 

I implemented the workaround you suggested and it works well!

	subroutine host()
		procedure(dummy_function), pointer :: nested_ptr
		nested_ptr => nested
		call with_dummy_function(nested_ptr)
	contains
		function nested()
			logical :: nested
			nested = .true.
		end function
	end subroutine

	subroutine with_dummy_function(func)
		procedure(dummy_function), pointer, intent(in) :: func
	end subroutine

Best regards

Ferdinand

0 Kudos
Steven_L_Intel1
Employee
1,684 Views

It's really simple - if you don't use "abstract", you are declaring an external procedure which is assumed to exist. With "abstract", you're just defining the interface.

0 Kudos
Steven_L_Intel1
Employee
1,684 Views

I expect the problem to be fixed in Update 1 to Parallel Studio XE 2017. If it doesn't make that, then Update 2.

0 Kudos
Reply