- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello all,
I'm using Visual Fortran 11 on Windows 32 and I found a problem when I'm trying to use a procedure pointer as a result of a function. I'm getting the error 'Program Exception - access violation'. Here is the code:
Do you think this is a bug of Visual Fortran ? If so, can it be corrected ?
Thanks a lot in advance !
Regards,
Gregory
I'm using Visual Fortran 11 on Windows 32 and I found a problem when I'm trying to use a procedure pointer as a result of a function. I'm getting the error 'Program Exception - access violation'. Here is the code:
[cpp]However, when I use a subroutine instead of a function, it's working fine :PROGRAM MAIN use TestMod implicit none type(object_ptproc) ptproc external DummyFunc ptproc = test_ptproc(DummyFunc) call ptproc%pt(2) END PROGRAM MAINsubroutine DummyFunc(n) implicit none integer, intent(in) :: n print*, n end subroutine DummyFunc [/cpp]module TestMod abstract interface subroutine OutputFunc(n) integer, intent(in):: n end subroutine OutputFunc end interface type object_ptproc procedure(OutputFunc), nopass, pointer :: pt => NULL() end type object_ptproc CONTAINS function test_ptproc(OutputFcn) result(ptproc) implicit none type(object_ptproc) :: ptproc external OutputFcn ptproc%pt => OutputFcn end function test_ptproc end module TestMod
[cpp]PROGRAM MAIN
use TestMod
implicit none
type(object_ptproc) ptproc
external DummyFunc
call test_ptproc(ptproc,DummyFunc)
call ptproc%pt(2)
END PROGRAM MAIN
subroutine DummyFunc(n)
implicit none
integer, intent(in) :: n
print*, n
end subroutine DummyFunc
module TestMod
abstract interface
subroutine OutputFunc(n)
integer, intent(in):: n
end subroutine OutputFunc
end interface
type object_ptproc
procedure(OutputFunc), nopass, pointer :: pt => NULL()
end type object_ptproc
CONTAINS
subroutine test_ptproc(ptproc,OutputFcn)
implicit none
type(object_ptproc), intent(out) :: ptproc
external OutputFcn
ptproc%pt => OutputFcn
end subroutine test_ptproc
end module TestMod[/cpp]
Do you think this is a bug of Visual Fortran ? If so, can it be corrected ?
Thanks a lot in advance !
Regards,
Gregory
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, there was a problem when I copy-pasted the first code. Here is the right one:
PROGRAM MAIN
use TestMod
implicit none
type(object_ptproc) ptproc
external DummyFunc
ptproc = test_ptproc(DummyFunc)
call ptproc%pt(2)
END PROGRAM MAIN
subroutine DummyFunc(n)
implicit none
integer, intent(in) :: n
print*, n
end subroutine DummyFunc
module TestMod
abstract interface
subroutine OutputFunc(n)
integer, intent(in):: n
end subroutine OutputFunc
end interface
type object_ptproc
procedure(OutputFunc), nopass, pointer :: pt => NULL()
end type object_ptproc
CONTAINS
function test_ptproc(OutputFcn) result(ptproc)
implicit none
type(object_ptproc) :: ptproc
external OutputFcn
ptproc%pt => OutputFcn
end function test_ptproc
end module TestMod
PROGRAM MAIN
use TestMod
implicit none
type(object_ptproc) ptproc
external DummyFunc
ptproc = test_ptproc(DummyFunc)
call ptproc%pt(2)
END PROGRAM MAIN
subroutine DummyFunc(n)
implicit none
integer, intent(in) :: n
print*, n
end subroutine DummyFunc
module TestMod
abstract interface
subroutine OutputFunc(n)
integer, intent(in):: n
end subroutine OutputFunc
end interface
type object_ptproc
procedure(OutputFunc), nopass, pointer :: pt => NULL()
end type object_ptproc
CONTAINS
function test_ptproc(OutputFcn) result(ptproc)
implicit none
type(object_ptproc) :: ptproc
external OutputFcn
ptproc%pt => OutputFcn
end function test_ptproc
end module TestMod
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's a compiler bug. In version 11.0, test_ptproc is not returning the pointer correctly. This is fixed in version 11.1, coming out in a few months.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page