Prototyping a Procedure in Fortran

You define a prototype (interface block) in your Fortran source code to tell the Fortran compiler which language conventions you want to use for an external reference. The interface block is introduced by the INTERFACE statement. See "Program Units and Procedures" in the Language Reference for a description of the INTERFACE statement.

The general form for the INTERFACE statement is:

INTERFACE

routine statement

[routine ATTRIBUTE options]

[argument ATTRIBUTE options]

formal argument declarations

END routine name

END INTERFACE

The routine statement defines either a FUNCTION or a SUBROUTINE, where the choice depends on whether a value is returned or not, respectively. The optional routine ATTRIBUTE options (such as C) determine the calling, naming, and argument-passing conventions for the routine in the prototype statement. The optional argument ATTRIBUTE options (such as VALUE and REFERENCE) are properties attached to individual arguments. The formal argument declarations are Fortran data type declarations. Note that the same INTERFACE block can specify more than one procedure.

For example, suppose you are calling a C function that has the following prototype:

  extern void My_Proc (int i);

The Fortran call to this function should be declared with the following INTERFACE block:

  INTERFACE     SUBROUTINE my_Proc (I)      !DEC$ ATTRIBUTES C, ALIAS:'My_Proc' :: my_Proc      INTEGER I     END SUBROUTINE my_Proc  END INTERFACE

Note that, except in the ALIAS string, the case of My_Proc in the Fortran program does not matter.