<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Calling atexit() from Fortran in Intel® Fortran Compiler</title>
    <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-atexit-from-Fortran/m-p/758361#M13848</link>
    <description>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. &lt;BR /&gt;&lt;BR /&gt;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().&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Oct 2011 11:10:27 GMT</pubDate>
    <dc:creator>mriedman</dc:creator>
    <dc:date>2011-10-06T11:10:27Z</dc:date>
    <item>
      <title>Calling atexit() from Fortran</title>
      <link>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-atexit-from-Fortran/m-p/758361#M13848</link>
      <description>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. &lt;BR /&gt;&lt;BR /&gt;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().&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Oct 2011 11:10:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Fortran-Compiler/Calling-atexit-from-Fortran/m-p/758361#M13848</guid>
      <dc:creator>mriedman</dc:creator>
      <dc:date>2011-10-06T11:10:27Z</dc:date>
    </item>
  </channel>
</rss>

