Replacing Intel Fortran ATTRIBUTES with C Interoperability Features

For many years, Fortran programmers have used vendor extensions to facilitate programming that mixes code written in Fortran and C. The Fortran 2003 standard defined new language features for C interoperability, and in many cases these can be used instead of vendor extensions.

This article lists, for each Intel Fortran extension commonly used for mixed-language programming, the corresponding standard Fortran syntax, if any. Please note that existing code will continue to work, but we encourage you to use the standard syntax when writing new code.

ATTRIBUTES ALIAS

Use BIND(C,NAME="alias-name"). The BIND(C) syntax also implies ATTRIBUTES DECORATE - the compiler applies whatever name decoration (leading or trailing underscores) that C would use for the exact same name.  Note that if the NAME= clause is omitted, Fortran will use the Fortran name converted to lowercase on all platforms.

For example, instead of:

INTERFACE
  SUBROUTINE CSUB
  !DEC$ ATTRIBUTES DECORATE, ALIAS:"CSub" :: CSUB
  END SUBROUTINE
END INTERFACE
You could use:
INTERFACE
  SUBROUTINE CSUB () BIND(C,NAME="CSub")
  END SUBROUTINE CSUB
END INTERFACE
Note that if the procedure has no arguments, you must indicate that with () when adding BIND. Also, all arguments to a routine specified as "interoperable" (with BIND(C)) must themselves be interoperable.   You can also specify BIND(C) on module variables and COMMON blocks.

ATTRIBUTES C

BIND(C), see ALIAS above, has a similar effect to ATTRIBUTES C except that it does not change the argument passing mechanism to be by-value; use the Fortran standard VALUE attribute if you need that.  BIND(C) also specifies that small records are passed and returned as function value results the same way C would, which may be different from the Intel Fortran default.  Like ATTRIBUTES C, BIND(C) downcases the external name and adds any necessary name decoration.

ATTRIBUTES DECORATE

This is typically used with ATTRIBUTES ALIAS.  See the section on ATTRIBUTES ALIAS above.

ATTRIBUTES DEFAULT

If you use BIND(C), this is not needed - the compiler always uses the semantics of the C compiler regardless of the setting of command-line options such as "iface".

ATTRIBUTES EXTERN

Use BIND(C) with a module variable.

ATTRIBUTES REFERENCE

This is typically used with character arguments, or to override the implicit pass-by-value of ATTRIBUTES C. It is never necessary when using BIND(C).

ATTRIBUTES STDCALL


Intel Fortran does not support use of STDCALL with BIND(C) at this time, so if you are interfacing to STDCALL routines (Windows on IA-32 architecture only), you must continue to use the ATTRIBUTES extension, along with ALIAS and DECORATE as required.

ATTRIBUTES VALUE

Use the Fortran-standard VALUE attribute instead.  Note that this has a subtle additional effect when used with a Fortran procedure - the dummy argument is received by value and then copied to a temporary variable that can be modified within the procedure.  Once the procedure exits, the temporary value is discarded.

Example of use:

SUBROUTINE MYSUB (ARG) BIND(C)
INTEGER, VALUE :: ARG
...
Note that the VALUE attribute may be used independently of BIND(C).

ATTRIBUTES VARYING

No equivalent.

%LOC function

The C_LOC function from intrinsic module ISO_C_BINDING may be an appropriate substitute for variables.  C_FUNLOC is the corresponding function for procedures.

%VAL function

Declare the argument with the VALUE attribute.

%REF function

This is the default when BIND(C) is used.
For more complete information about compiler optimizations, see our Optimization Notice.