Next: , Previous: Interoperability with C, Up: Mixed-Language Programming


7.2 GNU Fortran Compiler Directives

The Fortran standard describes how a conforming program shall behave; however, the exact implementation is not standardized. In order to allow the user to choose specific implementation details, compiler directives can be used to set attributes of variables and procedures which are not part of the standard. Whether a given attribute is supported and its exact effects depend on both the operating system and on the processor; see C Extensions for details.

For procedures and procedure pointers, the following attributes can be used to change the calling convention:

Besides changing the calling convention, the attributes also influence the decoration of the symbol name, e.g., by a leading underscore or by a trailing at-sign followed by the number of bytes on the stack. When assigning a procedure to a procedure pointer, both should use the same calling convention.

On some systems, procedures and global variables (module variables and COMMON blocks) need special handling to be accessible when they are in a shared library. The following attributes are available:

For dummy arguments, the NO_ARG_CHECK attribute can be used; in other compilers, it is also known as IGNORE_TKR. For dummy arguments with this attribute actual arguments of any type and kind (similar to TYPE(*)), scalars and arrays of any rank (no equivalent in Fortran standard) are accepted. As with TYPE(*), the argument is unlimited polymorphic and no type information is available. Additionally, the argument may only be passed to dummy arguments with the NO_ARG_CHECK attribute and as argument to the PRESENT intrinsic function and to C_LOC of the ISO_C_BINDING module.

Variables with NO_ARG_CHECK attribute shall be of assumed-type (TYPE(*); recommended) or of type INTEGER, LOGICAL, REAL or COMPLEX. They shall not have the ALLOCATE, CODIMENSION, INTENT(OUT), POINTER or VALUE attribute; furthermore, they shall be either scalar or of assumed-size (dimension(*)). As TYPE(*), the NO_ARG_CHECK attribute requires an explicit interface.

The attributes are specified using the syntax

!GCC$ ATTRIBUTES attribute-list :: variable-list

where in free-form source code only whitespace is allowed before !GCC$ and in fixed-form source code !GCC$, cGCC$ or *GCC$ shall start in the first column.

For procedures, the compiler directives shall be placed into the body of the procedure; for variables and procedure pointers, they shall be in the same declaration part as the variable or procedure pointer.