可分配数组、指针数组以及假定形状数组参数均使用数组描述符(也称为涂料矢量)。
任何编译器都可以有自己的数组描述符结构。它可以在编译器手册中找到。但描述符有一个标准化格式,用于与 C 进行通信(以及 Fortran 之外可能与 C 进行通信的其他软件)。
这个标准描述符可能不会被编译器内部使用,但它可以。如果它也在内部使用,那么编译器在调用 C 互操作过程时不必准备新的描述符。例如,gfortran计划支持标准描述符“最好是原生格式” https://gcc.gnu.org/wiki/ArrayDescriptorUpdate.
Intel 描述了一个与 C 互操作描述符不同的本机数组描述符示例:https://software.intel.com/en-us/node/678452 https://software.intel.com/en-us/node/678452.
C 互操作数组参数的数组描述符的结构由以下定义:关于 Fortran 与 C 的进一步互操作性的技术规范 ISO/IEC TS 29113:2012,它将成为 Fortran 2015 的一部分。
在C头文件中ISO_Fortran_binding.h
被定义为用 Fortran 描述符(假定的形状、指针或可分配的)定义的 C 结构。
它看起来如下(从IBM 网站 https://www.ibm.com/support/knowledgecenter/SSGH4D_15.1.0/com.ibm.xlf151.aix.doc/language_ref/interop-iso-f-binding-def.html,某些细节可能是编译器特定的):
CFI_cdesc_t
A type definition that describes a C descriptor. It contains the following structure members:
void *base_addr
The base address of the data object that is described. For deallocated allocatable objects, base_addr is NULL.
size_t elem_len
For scalars: The size in bytes of the data object that is described.
For arrays: The size in bytes of one element of the array.
int version
The version number of the C descriptor. Currently, the only valid value is available by using the CFI_VERSION macro.
CFI_attribute_t attribute
The attribute code of the C descriptor. For the valid values for attribute, see Table 1.
CFI_type_t type
The type code of the C descriptor. Describes the type of the object that is described by the C descriptor. For the valid values for type, see Table 2.
CFI_rank_t rank
The rank of the object that is described by the C descriptor. Its value must be in the range 0 ≤ rank ≤ CFI_MAX_RANK. A value of 0 indicates that the object is a scalar. Otherwise, the object is an array.
CFI_dim_t dim[]
An array of size rank that describes the lower bound, extent, and stride of each dimension.
There is a reserved area between rank and dim. The size of the reserved area is 12 words in 32-bit mode and 9 words in 64-bit mode.
所引用的CFI_
类型也定义在ISO_Fortran_binding.h
header.
因此,尽管此描述符可能与编译器内部使用的不完全相同,但它是一个很好的示例,说明 Fortran 数组描述符中应该包含哪种数据组件。
但是,请注意,gfortran(一种非常常见的编译器)尚未使用这种类型的描述符。只有一个使用新描述符的实验版本 https://gcc.gnu.org/wiki/ArrayDescriptorUpdate当前描述符在手册中有描述。状态也提到了Fortran 与 C 的进一步互操作性 https://gcc.gnu.org/onlinedocs/gfortran/Further-Interoperability-of-Fortran-with-C.html.