next up previous contents
Next: Examples of Data Type Up: C Language Bindings Previous: Specification of Interfaces to

Specification of Data Type Mappings for C

The extrinsic dummy argument feature, consisting of the MAP_TO, LAYOUT, and PASS_BY attributes, is the principal feature that facilitates referencing procedures defined in C from within Fortran programs. Together, these attributes allow the user to specify conversions required to associate the actual arguments specified in the procedure reference with the formal arguments defined by the referenced procedure. In particular, the MAP_TO attribute indicates the type of the C data to which the HPF data shall be converted by the compiler; the PASS_BY attribute indicates whether a C pointer to the dummy argument needs to be passed; the LAYOUT attribute indicates for an array whether the array element order needs to be changed from Fortran's array element ordering to C's.

For C, the constraints associated with attr-spec-extended, map-to-spec, layout-spec, and pass-by-spec (H1102-H1105) are further extended as follows.

If the compiler is capable of representing letters in both upper and lower case, the value specified for a map-to-spec, layout-spec or pass-by-spec is without regard to case. Any blanks specified for a map-to-spec, layout-spec or pass-by-spec shall be ignored by the compiler for the purposes of determining its value.

An implementation shall provide a module, ISO_C, that shall define a derived type, C_VOID_POINTER. The components of the C_VOID_POINTER type shall be private.

The values permitted for a map-to-spec for LANGUAGE = "0DC"0D are "0DINT"0D, "0DLONG"0D, "0DSHORT"0D, "0DSIGNED_CHAR"0D, "0DFLOAT"0D, "0DDOUBLE"0D, "0DLONG_DOUBLE"0D, "0DCHAR"0D, "0DCHAR_PTR"0D, "0DVOID_PTR"0D, or a comma-separated list, delimited by parentheses, of any of these values. The HPF types with which these are compatible are shown in the table below.

A map-to-spec that is a parenthesized list of values is compatible with a dummy argument of derived type if each value in the list is compatible with the corresponding component of the derived type.

When the PASS_BY attribute is used, the values permitted for a pass-by-spec are "0DVAL"0D, "0D*"0D, or "0D**"0D. If no PASS_BY attribute is specified, then PASS_BY ("0DVAL"0D) is assumed. If a pass-by-spec of VAL is specified, the dummy argument shall not have the INTENT(OUT) or INTENT(INOUT) attribute specified. If a value of "0D*"0D or "0D**"0D is specified for the pass-by-spec, an associated actual argument shall be a variable.

The value of the map-to-spec specified for a dummy argument in the interface body of a procedure for which a LANGUAGE= specifier whose value is C appears shall be such that at least one of the permitted mapped-to types is the same as the C data type of the corresponding formal argument in the C definition of the procedure (or a type that is compatible with one of the permitted mapped-to types). The C data type of a function in the C definition of a procedure shall be one of the permitted mapped-to types (or a type that is equivalent to the permitted mapped-to types) specified for the function result variable in the interface body of a function with the LANGUAGE= specifier whose value is C. If a subroutine has been specified with a LANGUAGE= specifier whose value is C, the C definition of the procedure shall be specified with a data type of void.

The permitted mapped-to types for scalar dummy arguments of intrinsic type or of the derived type C_VOID_POINTER, are shown in the following table.
MAP_TOCompatible WithC Type if PASS_BY
'VAL''*''**'
'INT'INTEGERintint*int**
'LONG'INTEGERlonglong*long**
'SHORT'INTEGERshortshort*short**
'SIGNED_CHAR'INTEGERsigned charsigned char*signed char**
'FLOAT'REALfloatfloat*float**
'DOUBLE'REALdoubledouble*double**
'LONG_DOUBLE'REALdoubledouble*double**
'CHAR'CHARACTER(1)charchar*char**
'CHAR_PTR'CHARACTERchar*char**char***
'VOID_PTR'C_VOID_POINTERvoid*void**void***

The permitted mapped-to types of an array are the same as the permitted mapped-to types of a scalar variable of that type followed by a left bracket ([), followed by the extent of the corresponding dimension of the dummy argument, followed by a right bracket (]), for each dimension of the array. If no value is specified for the LAYOUT attribute, the corresponding dimensions of the dummy argument are determined from right to left; if the value C_ARRAY is specified for the LAYOUT attribute, the corresponding dimensions of the dummy argument are determined from left to right.

The value permitted for a LANGUAGE = "0DC"0D layout-spec is C_ARRAY.

The permitted mapped-to types of a scalar variable of derived type are the structures whose corresponding members are of one of the permitted mapped-to types of the components of the derived type.

If there is a mismatch between the precision, representation method, range of permitted values or storage sequence between the type of the dummy argument and the permitted mapped-to type of the dummy argument, the compiler shall ensure that, for the duration of the reference to a procedure defined with a LANGUAGE= specifier whose value is C, the dummy argument is represented in a manner that is compatible with the expectations of the C processor for an object of the permitted mapped-to type. Upon return from the procedure, the compiler shall ensure that the value of an actual argument that is a variable is restored to the specified type and kind.

If the range of permitted values of the type and mapped-to type differ and the value of the actual argument or some subobject of the actual argument is not within the permitted range of the mapped-to type, the value of the associated dummy argument or subobject becomes undefined. Conversely, if the value of the dummy argument or some subobject of the dummy is not within the permitted range of values of the associated dummy argument, and the associated actual argument is a variable, the value of the associated actual argument or subobject of the actual becomes undefined.

If no layout-spec is specified for a dummy array argument, the array element order shall be the same as that specified by Fortran. If the value of layout-spec specified is C_ARRAY, the array element order of the array shall be transposed for the duration of the reference to the procedure.




next up previous contents
Next: Examples of Data Type Up: C Language Bindings Previous: Specification of Interfaces to