- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a problem calling a dummy callback from Fortran.
We have a C++ program which calls Fortran code, EQCONTOUR.
It passes a function pointer (FCALL) when calling this subroutine.
The purpose is to provide a callback function that the Fortran can call back in the C++ world to echo progress, etc.
This all works fine and here is the code:
EQCONTOUR uses this module:
module GUI_OLI
implicit none
save
interface
integer function GUI_FCALL(TEMP,PRES,IPT,JPT,KERR)
REAL*8 , intent(in) :: TEMP, PRES
INTEGER, intent(in) :: IPT, JPT
INTEGER, intent(out) :: KERR
end function
end interface
pointer (p_GUI_FCALL, GUI_FCALL)
end module GUI_OLI
Here is EQCONTOUR:
SUBROUTINE EQCONTOUR(FCALL)
USE GUI_OLI
IMPLICIT NONE
INTEGER :: FCALL
p_GUI_FCALL = FCALL
...
IF(GUI_FCALL(TEMP,PRES,IT,IP,KERR) == 0) THEN
...
RETURN
END
This works fine when EQCONTOUR is called from C++.
The problem comes when I want to test calling EQCONTOUR from Fortran.
Here is my code:
PROGRAM TEST
IMPLICIT NONE
INTEGER, EXTERNAL :: FCALL
!
call EQCONTOUR(FCALL)
END
! dummy FCALL
integer function FCALL(TEMP,PRES,IPT,JPT,KERR)
REAL*8 , intent(in) :: TEMP, PRES
INTEGER, intent(in) :: IPT, JPT
INTEGER, intent(out) :: KERR
FCALL = 1
KERR = 0
end function
When I try to call from Fortran as above, I get an access violation on the
IF(GUI_FCALL(... line.
I'm not sure why.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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