内在类型与原始非内在类型

Intrinsic type vs. primitive non-intrinsic type

我在 fortran 中遇到了这个词 'intrinsic type',我以前从未听过它:

Fortran has five intrinsic data types: integer, real, complex, logical, and character.

intrinsic 和"primitive"是同一个东西还是意思上有细微差别?什么是内在类型的对立面(我会想象像日期或小数点):那叫什么?

Fortran 标准将 intrinsic(通常,不仅针对类型)定义为:

1.3.93

intrinsic

type, procedure, module, assignment, operator, or input/output operation defined in this part of ISO/IEC 153917 and accessible without further definition or specification, or a procedure or module provided by a processor but not defined in this part of ISO/IEC 1539.

此外,它定义了如下的内在类型:

1.3.147.8

intrinsic type

type defined by this part of ISO/IEC 1539 that is always accessible.

因此,内部类型和派生类型之间的主要区别在于您必须 导入库才能使用最后一个。 (我之前使用 ISO_FORTRAN_ENV 库中的 real(real64) 做了一个 non-intrinsic 的例子,但正如 francescalus 在评论中指出的那样,事实并非如此。 )

您可能还想查看标准的 session 4.4,它专门详细处理了内在类型。 Fortran 标准 copy I have 是非官方的,也不是最新的标准,但作为 Fortran 哲学的一部分,最新的标准符合旧标准。

我没有在 Fortran 标准中找到 primitive 的匹配项,所以我相信 Fortran 中没有使用这个命名法。我也检查了 C 标准,并没有真正找到任何官方的东西,但是我在其他语言中找到的每个术语定义 - 例如在 Java - 基本上将它定义为语言附带的类型,即,固有的。 :)

也许您正在寻找的不同之处在于,虽然 real 是 Fortran 中的固有类型,但 double precision 不是:

The type specifier for the real type uses the keyword REAL. The keyword DOUBLE PRECISION is an alternative specifier for one kind of real type. If the type keyword REAL is used without a kind type parameter, the real type with default real kind is specified and the kind value is KIND (0.0). The type specifier DOUBLE PRECISION specifies type real with double precision kind; the kind value is KIND (0.0D0). The decimal precision of the double precision real approximation method shall be greater than that of the default real method.

然而,在其他语言中,shortlong等类型可能被理解为不同的原语。

内在类型是由 Fortran 标准定义并且始终可访问的数据类型之一(rvbarreto 的回答包含明确的定义引用)。截至 Fortran 2018,这些是问题中的五个。

在 Fortran 90 引入种类参数系统之前,存在类型 double precision 但这现在不是一个不同的内在类型:它指的是具有特定种类参数的内在类型 real .

与内在类型不同的是类似的东西:一种始终可访问但由特定处理器(编译器)定义的类型。一个示例可以是 byte 数据类型。

此外,还有派生数据类型。这些不是固有的,可以由用户或处理器定义。 c_ptr 等派生类型可能由 Fortran 标准定义,但因为它是在内部模块 iso_c_binding 中定义的,所以它并不总是可访问的:它不是内部类型。

用户定义的派生数据类型可能类似于:

type :: date
   real :: seconds_since_epoch
end type date

type :: decimal(digits)
   integer, kind :: digits
   integer :: value(digits)
end type decimal

这些并不总是可访问的(由用户定义)并且未由标准定义。


术语非固有 由标准定义,但这不适用于数据类型(只是模块和过程)。 "data types which are not intrinsic" 没有定义的术语。我们可以使用 derived typenon-standard type ,具体取决于我们想要捕获的上述情况。 "primitive" 可能更倾向于采用非标准处理器定义的数据类型。

考虑:

real a ! Intrinsic
byte b ! Non-standard 'primitive' perhaps (if supported)
type(byte) c ! Derived type, non-standard/user
type(c_ptr) d ! Standard (if referring to that of iso_c_binding)
type(real) e ! Intrinsic!
double precision f ! Intrinsic (real)