- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure whether or not there is a more elegant way of implementing module finalizer routines in Fortran. If yes, please let me know.
Otherwise feel free to use thisdemo code which makes use of the ISO C bindings and POSIX atexit() function and demonstrates how Fortran routines can be passed as an argument to atexit().
Otherwise feel free to use thisdemo code which makes use of the ISO C bindings and POSIX atexit() function and demonstrates how Fortran routines can be passed as an argument to atexit().
[fortran]module atexit_demo
use, intrinsic :: iso_c_binding
implicit none
interface
function atexit(fptr) bind(c)
use, intrinsic :: iso_c_binding
type(c_funptr), value, intent(in) :: fptr
integer(4) :: atexit
end function
end interface
public
contains
subroutine init
integer :: ierr
type(c_funptr) :: fptr
fptr = c_funloc(called_on_exit)
print *,'calling atexit'
ierr = atexit(fptr)
print *,'atexit error', ierr
end subroutine init
subroutine called_on_exit
print *,'Bye'
end subroutine called_on_exit
end module atexit_demo
[/fortran]
Link Copied
0 Replies
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