Intel® Fortran Compiler

Developer Guide and Reference

ID 767251
Date 3/31/2025
Public

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

Visible to Intel only — GUID: GUID-5A3F7F99-BD41-4520-91A9-8022AD31375D

Document Table of Contents

ATTRIBUTES Directive Properties

Standard Fortran provides a syntax for interoperating with C, including applying the appropriate naming conventions. You should use BIND(C) for interoperability with C, instead of specifying ATTRIBUTES properties. Do not specify both BIND(C) and ATTRIBUTES C for the same procedure. Specifying ATTRIBUTES STDCALL has no effect if BIND(C) is also specified for the same procedure.

The ATTRIBUTES properties C, STDCALL (Windows only), REFERENCE, and VALUE affect the calling convention of routines. You can specify:

  • The C and STDCALL properties for an entire routine.

  • The VALUE and REFERENCE properties for individual arguments.

By default, Fortran passes all data by reference (except the hidden length argument of strings, which is passed by value). If the C (or STDCALL) property is used, the default changes to passing almost all data except arrays by value. However, in addition to the calling-convention properties C and STDCALL, you can specify properties VALUE and REFERENCE to pass arguments by value or by reference, regardless of the calling convention option. Arrays can only be passed by reference.

Different Fortran calling conventions can be specified by declaring the Fortran procedure to have certain attributes.

The following table summarizes the effect of the most common Fortran calling convention directives.

Argument

Default

C or STDCALL

C, REFERENCE or STDCALL, REFERENCE

Scalar

Reference

Value

Reference

Scalar [value]

Value

Value

Value

Scalar [reference]

Reference

Reference

Reference

String

Reference, either Len:End or Len:Mixed

String(1:1)

Reference, either Len:End or Len:Mixed

String [value]

Error

String(1:1)

String(1:1)

The naming conventions are shown in the following table.

Argument

Default

C or STDCALL

C, REFERENCE or STDCALL, REFERENCE

Prefix

none

none

none

Suffix

none (Windows)

_ (Linux)

none

none

Case

Upper Case (Windows)

Lower Case (Linux)

Lower Case

Lower Case

Stack Cleanup

Caller

Caller

Caller

The terms in the previous tables mean the following:

Term Term Meaning

[value]

Argument assigned the VALUE attribute.

[reference]

Argument assigned the REFERENCE attribute.

Value

The argument value is pushed to the stack. All values are padded to the next 4-byte boundary.

Reference

The 8-byte argument address is pushed to the stack.

Len:End or Len:Mixed

For certain string arguments:

  • Len:End applies when -nomixed-str-len-arg (Linux) or /iface:nomixed_str_len_arg (Windows) is set. The length of the string is pushed (by value) on the stack after all of the other arguments. This is the default.

  • Len:Mixed applies when -mixed-str-len-arg (Linux) or /iface:mixed_str_len_arg (Windows) is set. The length of the string is pushed (by value) on the stack immediately after the address of the beginning of the string.

You can use the BIND attribute to resolve discrepancies with C. Alternatively, the ALIAS property can be used with any other Fortran calling-convention option to preserve mixed-case names.

On Windows, the compiler option /iface also establishes some default argument passing conventions. Option /iface has the following choices:

Option

Argument Is Passed By

Who Cleans the Stack?

Varargs Support?

/iface:cref

By reference

Caller

Yes

/iface:stdref

By reference

Callee

No

/iface:default

By reference

Caller

Yes

/iface:c

By value

Caller

Yes

/iface:stdcall

By value

Callee

No

NOTE:

On Windows, when interfacing to the Windows GUI or making API calls, you will typically use STDCALL.