concept fortran interface in category fortran

appears as: Fortran interface, A Fortr interface, Fortr interface, Fortr interface
Modern Fortran: Building efficient parallel applications

This is an excerpt from Manning's book Modern Fortran: Building efficient parallel applications.

Our first step is to write a Fortran interface with the C struct ipaddr in the libdill library. This is the first ingredient we need to get before implementing the ipaddr_local (server) and ipaddr_remote (client) functions. A struct in C is analogous to a derived type in Fortran (see chapter 8)--an arbitrary data structure with components of built-in or other data types. For the most part, they have a similar syntax and behavior.

Although the functions ipaddr_local and ipaddr_remote are described in the documentation, the ipaddr struct that they use as an argument isn’t. To understand how to write a Fortran interface with this struct, we need to look inside the libdill header file. If you installed libdill following the instructions in the previous subsection, you’ll find the file here: libdill-2.14/libdill.h. The relevant snippet that gives the definition of the ipaddr struct in libdill.h is

Listing 11.1. A Fortran interface with the ipaddr struct
language="fortran" linenumbering="unnumbered">module mod_dill

  use iso_c_binding, only: c_char #1
  implicit none

  private
  public :: ipaddr

  type, bind(c, name='dill_ipaddr') :: ipaddr #2
    character(c_char) :: address(32) #3
  end type ipaddr #4

end module mod_dill