General Compiler Directive: Declares properties for specified variables.
Syntax
The following table shows which properties can be used with various objects:
Property | Variable
and Array Declarations |
Common Block Names 1 | Subprogram Specification and EXTERNAL Statements |
---|---|---|---|
ADDRESS64 | Yes | Yes | No |
ALIAS | No | Yes | Yes |
ALLOW_NULL | Yes | No | No |
ARRAY_VISUALIZER2 | Yes | No | No |
C | No | Yes | Yes |
DECORATE | No | No | Yes |
DEFAULT | No | Yes | Yes |
DESCRIPTOR | Yes3 | No | No |
DESCRIPTOR32 | Yes3 | No | No |
DESCRIPTOR64 | Yes3 | No | No |
DLLEXPORT | Yes4 | Yes | Yes |
DLLIMPORT | Yes | Yes | Yes |
EXTERN | Yes | No | No |
IGNORE_LOC | Yes3 | No | No |
NO_ARG_CHECK | Yes | No | Yes5 |
NOMIXED_STR_LEN_ARG | No | No | Yes |
REFERENCE | Yes | No | Yes |
REFERENCE32 | Yes | No | No |
REFERENCE64 | Yes | No | No |
STDCALL | No | Yes | Yes |
VALUE | Yes | No | No |
VARYING | No | No | Yes |
1 A common block name is specified
as [/]common-block-name[/]
2 This property can only be applied to arrays. 3 This property can only be applied to INTERFACE blocks. 4 Module-level variables and arrays only. 5 This property cannot be applied to EXTERNAL statements. |
These properties can be used in function and subroutine definitions, in type declarations, and with the INTERFACE and ENTRY statements.
Properties applied to entities available through use or host association are in effect during the association. For example, consider the following:
MODULE MOD1
INTERFACE
SUBROUTINE SUB1
!DEC$ ATTRIBUTES C, ALIAS:'othername' :: NEW_SUB
END SUBROUTINE
END INTERFACE
CONTAINS
SUBROUTINE SUB2
CALL NEW_SUB
END SUBROUTINE
END MODULE
In this case, the call to NEW_SUB within SUB2 uses the C and ALIAS properties specified in the interface block.
The properties are described as follows:
Specifies that the object has a 64-bit address. This property can be specified for any variable or dummy argument, including ALLOCATABLE and deferred-shape arrays. However, variables with this property cannot be data-initialized.
It can also be specified for COMMON blocks or for variables in a COMMON block. If specified for a COMMON block variable, the COMMON block implicitly has the ADDRESS64 property.
ADDRESS64 is not compatible with the AUTOMATIC attribute.
Specifies an alternate external name to be used when referring to external subprograms. Its form is:
The ALIAS property overrides the C (and STDCALL) property. If both C and ALIAS are specified for a subprogram, the subprogram is given the C calling convention, but not the C naming convention. It instead receives the name given for ALIAS, with no modifications.
ALIAS cannot be used with internal procedures, and it cannot be applied to dummy arguments.
The following example gives the subroutine happy the name "_OtherName@4" outside this scoping unit:
INTERFACE
SUBROUTINE happy(i)
!DEC$ ATTRIBUTES STDCALL, DECORATE, ALIAS:'OtherName' :: happy
INTEGER i
END SUBROUTINE
END INTERFACE
cDEC$ ATTRIBUTES ALIAS has the same effect as the cDEC$ ALIAS directive.
Enables a corresponding dummy argument to pass a NULL pointer (defined by a zero or the NULL intrinsic) by value for the argument.
ALLOW_NULL is only valid if the REFERENCE property is also specified; otherwise, it has no effect.
Enhances the performance of the Array Visualizer.
When declaring allocatable arrays to be viewed using the Array Viewer, this option can improve the performance of the Array Viewer. For example:
real(4), allocatable :: MyArray(:, :)
!DEC$ ATTRIBUTES array_visualizer :: MyArray
When this option is used, array memory is shared between the Array Viewer and your application. Otherwise, the array data is copied during each faglUpdate call.
This option is not useful unless the array is viewed in the Array Visualizer by using fagl* calls.
For more information on fagl* routines, see your online documentation for Array Visualizer.
Specify how data is to be passed when you use routines written in C or assembler with FORTRAN or Fortran 95/90 routines.
On ia32 processors, C and STDCALL have slightly different meanings; on all other platforms, they are interpreted as synonyms.
When applied to a subprogram, these properties define the subprogram as having a specific set of calling conventions.
The following table summarizes the differences between the calling conventions:
Convention | C 1 | STDCALL 1 | Default 2 |
---|---|---|---|
Arguments passed by value | Yes | Yes | No |
Case of external subprogram names | VMS: Uppercase
U*X: Lowercase WNT: Lowercase W95: Lowercase |
VMS: Uppercase
U*X: Lowercase WNT: Lowercase W95: Lowercase |
VMS: Uppercase
U*X: Lowercase WNT: Uppercase W95: Uppercase |
U*X only: | |||
Trailing underscore added | No | No | Yes 3 |
WNT, W9*: | |||
Leading underscore added | Yes | Yes | Yes |
Number of arguments added | No | Yes | Yes |
Caller stack cleanup | Yes | No | No |
Variable number of arguments | Yes | No | No |
1 C and STDCALL are synonyms on OpenVMS, Tru64 UNIX,
and Linux systems.
2 The Fortran 95/90 calling convention 3 On Linux systems, if there are one or more underscores in the external name, two trailing underscores are added; if there are no underscores, one is added. |
If C or STDCALL is specified for a subprogram, arguments (except for arrays and characters) are passed by value. Subprograms using standard Fortran 95/90 conventions pass arguments by reference.
On ia32 processors, an underscore ( _ ) is placed at the beginning of the external name of a subprogram. If STDCALL is specified, an at sign (@) followed by the number of argument bytes being passed is placed at the end of the name. For example, a subprogram named SUB1 that has three INTEGER(4) arguments and is defined with STDCALL is assigned the external name _sub1@12.
Character arguments are passed as follows:
On all systems, the first character of the string is passed (and padded with zeros out to INTEGER(4) length).
On all systems, the string is passed with no length.
On all systems, the string is passed with the length.
See also REFERENCE and Adjusting Calling Conventions in Mixed-Language Programming.
Specifies that the external name used in cDEC$ ALIAS or cDEC$ ATTRIBUTES ALIAS should have the prefix and postfix decorations performed on it that are associated with the calling mechanism that is in effect. These are the same decorations performed on the procedure name when ALIAS is not specified.
The case of the ALIAS external name is not modified.
If ALIAS is not specified, this option has no effect.
See also the example in the above description of the ATTRIBUTES option ALIAS, and the summary of prefix and postfix decorations in the above description of the ATTRIBUTES options C and STDCALL.
Overrides certain compiler options that can affect external routine and COMMON block declarations.
It specifies that the compiler should ignore compiler options that change the default conventions for external symbol naming and argument passing for routines and COMMON blocks (/iface, /names, and /assume:underscore).
This option can be combined with other cDEC$ ATTRIBUTES options, such as STDCALL, C, REFERENCE, ALIAS, etc. to specify attributes different from the compiler defaults.
This option is useful when declaring INTERFACE blocks for external routines, since it prevents compiler options from changing calling or naming conventions.
Specifies that the argument is passed by VMS descriptor. This property can be specified only for dummy arguments in an INTERFACE block (not for a routine name).
Specifies that the argument is passed as a 32-bit descriptor.
Specifies that the argument is passed as a 64-bit descriptor.
Define a dynamic-link library's (DLL) interface for processes that use them. The properties can be assigned to data objects or procedures.
DLLEXPORT specifies that procedures or data are being exported to other applications or DLLs. This causes the compiler to produce efficient code, eliminating the need for a module definition (.def) file to export symbols.
The DLLEXPORT property should be specified in the routine to which it applies.
Symbols defined in a DLL are imported by programs that use them. The program must link with the import DLL and use the DLLIMPORT property inside the program unit that imports the symbol. DLLIMPORT is specified in a declaration, not a definition, since you cannot define a symbol you are importing.
For details on working with DLL applications, see Creating Fortran DLLs in the Programmer's Guide.
Specifies that a variable is allocated in another source file. EXTERN can be used in global variable declarations, but it must not be applied to dummy arguments.
EXTERN must be used when accessing variables declared in other languages.
Enables %LOC to be stripped from an argument.
IGNORE_LOC is only valid if the REFERENCE property is also specified; otherwise, it has no effect.
Specifies that type and shape matching rules related to explicit interfaces are to be ignored. This permits the construction of an INTERFACE block for an external procedure or a module procedure that accepts an argument of any type or shape; for example, a memory copying routine.
NO_ARG_CHECK can appear only in an INTERFACE block for a non-generic procedure or in a module procedure. It can be applied to an individual dummy argument name or to the routine name, in which case the property is applied to all dummy arguments in that interface.
NO_ARG_CHECK can not be used for procedures with the PURE or ELEMENTAL prefix. If an argument has an INTENT or OPTIONAL attribute, any NO_ARG_CHECK specification is ignored.
Specifies that hidden lengths be placed in sequential order at the end of the argument list. This is the method used on Tru64 UNIX systems by default.
Specify how a dummy argument is to be passed.
REFERENCE specifies a dummy argument's memory location is to be passed instead of the argument's value.
VALUE specifies a dummy argument's value is to be passed instead of the argument's memory location.
When a dummy argument has the VALUE property, the actual argument passed to it can be of a different type. If necessary, type conversion is performed before the subprogram is called.
When a complex (KIND=4 or KIND=8) argument is passed by value, two floating-point arguments (one containing the real part, the other containing the imaginary part) are passed by immediate value.
Character values, substrings, assumed-size arrays, and adjustable arrays cannot be passed by value.
If REFERENCE (only) is specified for a character argument, the following occurs:
If REFERENCE is specified for a character argument, and C (or STDCALL) has been specified for the routine, the string is passed with no length. This is true even if REFERENCE is also specified for the routine.
If REFERENCE and C (or STDCALL) are specified for a routine, but REFERENCE has not been specified for the argument, the string is passed with the length.
VALUE is the default if the C or STDCALL property is specified in the subprogram definition.
In the following example integer x is passed by value:
SUBROUTINE Subr (x)
INTEGER x
!DEC$ ATTRIBUTES VALUE :: x
See also C and STDCALL and Adjusting Calling Conventions in Mixed-Language Programming.
Specifies that the argument is accepted only by 32-bit address.
Specifies that the argument is accepted only by 64-bit address.
Allows a variable number of calling arguments. If VARYING is specified, the C property must also be specified.
Either the first argument must be a number indicating how many arguments to process, or the last argument must be a special marker (such as -1) indicating it is the final argument. The sequence of the arguments, and types and kinds must be compatible with the called procedure.
Options C, STDCALL, REFERENCE, VALUE, and VARYING affect the calling conventions of routines:
The following form is also allowed for this attribute:
!MS$ATTRIBUTES att [,att] ... :: object [,object] ...
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also: Programming with Mixed Languages, Creating Fortran DLLs, General Compiler Directives
Examples
INTERFACE
SUBROUTINE For_Sub (I)
!DEC$ ATTRIBUTES C, ALIAS:'_For_Sub' :: For_Sub
INTEGER I
END SUBROUTINE For_Sub
END INTERFACE
You can assign more than one property to multiple variables with the same compiler directive. All properties apply to all the specified variables. For example:
!DEC$ ATTRIBUTES REFERENCE, VARYING, C :: A, B, C
In this case, the variables A
, B
, and C
are assigned the REFERENCE, VARYING, and C properties. The only
restriction on the number of properties and variables is that the entire
compiler directive must fit on one line.
The identifier of the variable or procedure assigned properties must be a simple name. It cannot include initialization or array dimensions. For example, the following is not allowed:
!DEC$ ATTRIBUTES C :: A(10) ! This is illegal.
The following shows another example:
SUBROUTINE ARRAYTEST(arr)
!DEC$ ATTRIBUTES DLLEXPORT :: ARRAYTEST
REAL(4) arr(3, 7)
INTEGER i, j
DO i = 1, 3
DO j = 1, 7
arr (i, j) = 11.0 * i + j
END DO
END DO
END SUBROUTINE