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

procedure pointer in ifort 11.0

albapa
Beginner
1,442 Views

hi,

i've been playing around a bit with the new beta version, and I tried whether procedure pointers work. So I found the following:

the code below compiles and works nicely:

program test_pointer

interface
subroutine gen
endsubroutine gen
endinterface

procedure(gen), pointer :: r

r => my_r

call r

contains

subroutine my_r
print*,'hello'
endsubroutine my_r

endprogram test_pointer

whereas the slightly modified version gives an error message and won't compile:

program test_pointer

interface
subroutine gen(x)
integer :: x
endsubroutine gen
endinterface

procedure(gen), pointer :: r

r => my_r

call r(5)

contains

subroutine my_r(x)
integer :: x
print*,x
endsubroutine my_r

endprogram test_pointer

error message:

test_pointer.f95(11): error #8178: The procedure pointer and the procedure target must have matching arguments.
r => my_r
---^
compilation aborted for test_pointer.f95 (code 1)

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,442 Views

Interesting question. Offhand, I woukd think that if the first one worked the second should. This version works:

[cpp]program test_pointer

   abstract interface
      subroutine gen(x)
        integer :: x
      endsubroutine gen
   end interface

   procedure(gen), pointer :: r
   procedure(gen) :: my_r

   r => my_r

   call r(5)


endprogram test_pointer

     subroutine my_r(x)
        integer :: x
        print*,x
     endsubroutine my_r[/cpp]

I will ask the developers about this.

View solution in original post

0 Kudos
13 Replies
Steven_L_Intel1
Employee
1,443 Views

Interesting question. Offhand, I woukd think that if the first one worked the second should. This version works:

[cpp]program test_pointer

   abstract interface
      subroutine gen(x)
        integer :: x
      endsubroutine gen
   end interface

   procedure(gen), pointer :: r
   procedure(gen) :: my_r

   r => my_r

   call r(5)


endprogram test_pointer

     subroutine my_r(x)
        integer :: x
        print*,x
     endsubroutine my_r[/cpp]

I will ask the developers about this.

0 Kudos
albapa
Beginner
1,442 Views

[c-sharp]module stuff

 contains

 subroutine my_r(x)
 integer :: x
 print*,x
 endsubroutine my_r

endmodule stuff

program test_pointer

 use stuff
 interface
 subroutine gen(x)
 integer :: x
 endsubroutine gen
 endinterface

 procedure(gen), pointer :: r

 r => my_r

 call r(5)

endprogram test_pointer[/c-sharp]

this one works as well. It seems that the compilers has to know the explicit interface beforehand, but it's not the case when there are internal subroutines.

Thanks!

(I'm struggling posting this, only some stupid thing would be displayed...)

0 Kudos
Steven_L_Intel1
Employee
1,442 Views

I saw the problem you had with the post and will report it.

0 Kudos
albapa
Beginner
1,442 Views

btw, when are you going to support polymorphic types? I noticed this is not included in the features yet (although it's pretty close now!)

0 Kudos
Kevin_D_Intel
Employee
1,442 Views
We are not able to say exactly when. It will not be in the upcoming 11.0 Release. Steves guidance in earlier posts regarding the many F2003 features is that Everything is on the list. Its just a question of when.
0 Kudos
colbylemon
Beginner
1,442 Views
module stuff

contains

function my_r(x)
integer,dimension(3) :: x
real :: my_r
my_r = x(1)
endfunction my_r

endmodule stuff

program test_pointer

use stuff
interface
function gen(x)
integer,dimension(3) :: x
real :: gen
endfunction gen
endinterface
integer :: x(3)

procedure(gen), pointer :: r

r => my_r

write(*,*) r((/5,6,7/))

endprogram test_pointer

The code here is modified to turn x into an array argument. This gives the same error mentioned above, namely:

error #8178: The procedure pointer and the procedure target must have matching arguments.
r => my_r
-^

I would like to be able to use procedure pointers with array arguments (and array return values). Is there something obvious that I'm overlooking?
0 Kudos
Steven_L_Intel1
Employee
1,442 Views
The difference with your example and the original is the use of a module proceure. I think this is a compiler bug and have reported it as DPD200140446. The original issue in this thread was fixed in 11.1.
0 Kudos
colbylemon
Beginner
1,442 Views
The difference with your example and the original is the use of a module proceure. I think this is a compiler bug and have reported it as DPD200140446. The original issue in this thread was fixed in 11.1.

Yes, I apologize for not mentioning that I'm using the 11.1.067 version. I replied to this thread because of the similarity of the error message and topic, since I have a larger code that I am trying to compile and run with ifort, but seem to be running into this problem. I first tried compiling each of the code snippets mentioned in this thread to start from code that worked, modifying them until they were giving the error that I was finding in my much larger code.

I also changed the subroutine to a function. In my larger code, I'm using procedure pointers and procedure pointer components of derived types, and the arguments to the function targets that I'm using are 1d arrays and derived types, and the return value is a 1d array.

Thanks for reporting this!
0 Kudos
Gustavo_Colvero
Beginner
1,442 Views

The same thing here...
This trick seems to work only if the target procedure has a scalar argument.

Gustavo.

BTW: where is hidden the good F2003 documentation???




0 Kudos
Steven_L_Intel1
Employee
1,442 Views
Please provide an example which doesn't work for you.

You can find the Fortran 2003 standard here.
0 Kudos
germanariel
Beginner
1,442 Views
Dear all:

I have been having some trouble with procedure pointers. I am using Intel Fortran Compiler 11.1.064. Look at these examples:

1) This code produces no errors

------
module stuff
implicit none
end module stuff

program test_pointer
use stuff
implicit none
interface
function gen(x)
implicit none
real,dimension(:) :: x
real :: gen
endfunction gen
endinterface
procedure( gen ) , pointer :: r
r => f
contains
function f(x)
implicit none
real,dimension(:):: x
real :: f
f = x(1)
endfunction f
endprogram test_pointer
-------

2) The following slightly modified code does not work and compilation produces this error message:

prueba.f90(23): error #8178: The procedure pointer and the procedure target must have matching arguments.
r => f
--^
compilation aborted for prueba.f90 (code 1)

It seems that if the target procedure is in a module, then we face this error. Is this a bug?

-------
module stuff
implicit none
contains
function f(x)
implicit none
real,dimension(:):: x
real :: f
f = x(1)
endfunction f
end module stuff

program test_pointer
use stuff
implicit none
interface
function gen(x)
implicit none
real,dimension(:) :: x
real :: gen
endfunction gen
endinterface
procedure( gen ) , pointer :: r
r => f
endprogram test_pointer
---------



Quoting - Steve Lionel (Intel)
Please provide an example which doesn't work for you.

You can find the Fortran 2003 standard here.

0 Kudos
Steven_L_Intel1
Employee
1,442 Views
germanariel, this looks like a bug previously reported but not yet fixed. I'll look at our records on Monday.
0 Kudos
Steven_L_Intel1
Employee
1,442 Views
germanariel, this looks like a bug previously reported but not yet fixed. I'll look at our records on Monday.

Indeed, it's the same issue as above (DPD200140446). This is fixed in our sources - I expect the fix to appear in the late January update (Update 5).
0 Kudos
Reply