Calling C Procedures from an Intel Fortran Program

Naming Conventions

By default, the Fortran compiler converts function and subprogram names to lower case for Linux and Mac OS and upper case for Windows. The C compiler never performs case conversion. A C procedure called from a Fortran program must, therefore, be named using the appropriate case. For example, consider the following calls:

CALL PROCNAME()

The C procedure must be named PROCNAME.

X=FNNAME()

The C procedure must be named FNNAME

In the first call, any value returned by PROCNAME is ignored. In the second call to a function, FNNAME must return a value.

Passing Arguments Between Fortran and C Procedures

By default, Fortran subprograms pass arguments by reference; that is, they pass a pointer to each actual argument rather than the value of the argument. C programs, however, pass arguments by value. Consider the following:

For 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 (that is, /iface:mixed_str_len_arg).