ATTRIBUTES Properties and Calling Conventions

The ATTRIBUTES properties (also known as options) C, REFERENCE, VALUE, and VARYING all affect the calling convention of routines. You can specify the:

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

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

INTERFACE
SUBROUTINE MY_SUB (I)
   !DEC$ ATTRIBUTES C, ALIAS:'My_Sub_' :: MY_SUB ! IA-32 systems
   INTEGER I   END SUBROUTINE MY_SUB
END INTERFACE

This code declares a subroutine named MY_SUB with the C property and the external name My_Sub_ set with the ALIAS property.

For another example, the following declaration assumes the subroutine is called with the C calling convention:

SUBROUTINE CALLED_FROM_C (A)
  !DEC$ ATTRIBUTES C :: CALLED_FROM_C

  INTEGER A

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

Calling Conventions for ATTRIBUTES Properties

Argument

Default

C

C, 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)

String [reference]

Reference, either No Len or Len:Mixed

Reference, No Len

Reference, No Len

Array

Reference

Reference

Reference

Array [value]

Error

Error

Error

Array [reference]

Reference

Reference

Reference

Derived Type

Reference

Value, size dependent

Reference

Derived Type [value]

Value, size dependent

Value, size dependent

Value, size dependent

Derived Type [reference]

Reference

Reference

Reference

F90 Pointer

Descriptor

Descriptor

Descriptor

F90 Pointer [value]

Error

Error

Error

F90 Pointer [reference]

Descriptor

Descriptor

Descriptor

The procedure name is all lowercase for all the calling conventions.

The terms in the above table mean the following:

[value]

Argument assigned the VALUE attribute.

[reference]

Argument assigned the REFERENCE attribute.

Value

The argument value is pushed on the stack. All values are padded to the next 4-byte boundary for IA-32 based systems and to the next 8-byte boundary for Intel® EM64T and Itanium-based systems.

Reference

On IA-32 systems, the 4-byte argument address is pushed on the stack.
On Itanium®-based systems, the 8-byte argument address is pushed on the stack.

Len:End or Len:Mixed

For certain string arguments:

  • Len:End applies when -nomixed_str_len_arg 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 is set. The length of the string is pushed (by value) on the stack immediately after the address of the beginning of the string.

No Len or Len:Mixed

For certain string arguments:

  • No Len applies when -nomixed_str_len_arg is set. The length of the string is not available to the called procedure. This is the default.

  • Len:Mixed applies when -mixed_str_len_arg is set. The length of the string is pushed (by value) on the stack immediately after the address of the beginning of the string.

No Len

For string arguments, the length of the string is not available to the called procedure.

String(1:1)

For string arguments, the first character is converted to INTEGER(4) as in ICHAR(string(1:1)) and pushed on the stack by value.

Error

Produces a compiler error.

Descriptor

On IA-32 systems, the 4-byte address of the array descriptor.
On Itanium-based systems, the 8-byte address of the array descriptor.

Size dependent

On IA-32 systems, derived-type arguments specified by value are passed as follows:

  • Arguments from 1 to 4 bytes are passed by value.

  • Arguments from 5 to 8 bytes are passed by value in two registers (two arguments).

  • Arguments more than 8 bytes provide value semantics by passing a temporary storage address by reference.

The following table shows another Fortran ATTRIBUTES property that matches another language calling convention:

Other Language Calling Convention

Matching ATTRIBUTES Property

C/C++ cdecl (default)

C

The ALIAS property can be used with any other Fortran calling-convention property to preserve mixed-case names. You can also use the DECORATE property in combination with the ALIAS property to specify that the external name specified in ALIAS should have the correct prefix and postfix decorations for the calling mechanism in effect.