- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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_pointererror 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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I saw the problem you had with the post and will report it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page