- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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)
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
링크가 복사됨
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
[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...)
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
I saw the problem you had with the post and will report it.
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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!)
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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?
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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!
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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???
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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)
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
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).
