next up previous contents
Next: Fortran Language Bindings Up: Specification of Data Type Previous: Specification of Data Type

Examples of Data Type Mappings

 

Some examples should help to clarify what sorts of C procedure definitions would be permitted given an interface body in a Fortran program. For example, the following interface body

        INTERFACE
          EXTRINSIC('C') SUBROUTINE C_SUB(I, R, DARR, STRUCT)
            INTEGER, MAP_TO('INT') :: I
            REAL, MAP_TO('FLOAT'), PASS_BY('*') :: R
            REAL(KIND(1.0D0)), MAP_TO('DOUBLE') :: DARR(10)
            TYPE DT
              SEQUENCE
              INTEGER :: I, J
            END TYPE DT
            TYPE(DT), MAP_TO('(INT, LONG)'), PASS_BY('*') :: STRUCT
          END SUBROUTINE C_SUB
        END INTERFACE

could correspond to a C procedure that has the prototype

   void c_sub(int i, float r*, double darr[10], struct int i, long j *)

In the following example of the LAYOUT attribute,

      PROGRAM P
        INTERFACE
          EXTRINSIC('C') SUBROUTINE C_SUB(A, B)
            INTEGER, MAP_TO('INT') :: A(2,2)
            INTEGER, MAP_TO('INT'), LAYOUT('C_ARRAY') :: B(2,2)
          END SUBROUTINE C_SUB
        END INTERFACE

        INTEGER :: AA(2,2), BB(2,2)
        CALL C_SUB(AA, BB)
      END PROGRAM P

      void c_sub(int a[2][2], b[2][2])

the correspondence between elements of AA and a, and elements of BB and b is

        AA(1,1)   a[0][0]              BB(1,1)   b[0][0]
        AA(2,1)   a[0][1]              BB(2,1)   b[1][0]
        AA(1,2)   a[1][0]              BB(1,2)   b[0][1]
        AA(2,2)   a[1][1]              BB(2,2)   b[1][1]