Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 3/22/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Pass Arguments in Mixed-Language Programming

By default, Fortran programs pass arguments by reference. They pass a pointer to each actual argument rather than the value of the argument. C programs typically pass arguments by value. Consider the following:

  • When a Fortran program calls a C function, the C function's formal arguments must be declared as pointers to the appropriate data type.

  • When a C program calls a Fortran subprogram, each actual argument must be specified explicitly as a pointer.

You can pass data between Fortran and C/C++ using argument lists just as you can within each language (for example, the argument list a, b and c in CALL MYSUB(a,b,c)). You can pass individual arguments in two ways:

  • By value: Passes the argument's value.

  • By reference: Passes the address of the arguments. On systems based on IA-32 architecture, Fortran, C, and C++ use 4-byte addresses. On Intel® 64 architecture and IA-64 architecture, these languages use 8-byte addresses.

You need to make sure that for every call, the calling program and the called routine agree how each argument is passed. Otherwise, the called routine receives bad data.

The Fortran technique for passing arguments changes depending on the calling convention specified. By default, Fortran passes all data by reference (except the hidden length argument of strings, which is passed by value).

On Windows systems using IA-32 architecture only, you can alter the default calling convention. You can use either the /iface:stdcall option (stdcall) or the /iface:cvf option (Compaq and Powerstation compatibility) to change the default calling convention, or the VALUE or C attributes in an explicit interface using the ATTRIBUTES directive. For more information on the ATTRIBUTES directive, see the Intel® Fortran Language Reference.

Both options cause the routine compiled and routines that it calls to have a @<n> appended to the external symbol name, where n is the number of bytes of all parameters. Both options assume that any routine called from a Fortran routine compiled this way will do its own stack cleanup, callee pops. /iface:cvf also changes the way that CHARACTER variables are passed. With /iface:cvf, CHARACTER variables are passed as address/length pairs (/iface:mixed_str_len_arg).