我对值类型和 CIL 评估堆栈有点困惑。
ECMA-335, Partition III, §1.1 说 CLI 处理这些“基本 CLI 类型”:
A subset of the full numeric types (int32, int64, native int, and F).
Object references (O) without distinction between the type of object referenced.
Pointer types (native unsigned int and &) without distinction as to the type pointed to.
第 II 部分第 12.1 节也提供了一个类似的列表,其中不包括值类型,并指出:
However, the CLI supports only a subset of these types in its operations upon values stored on its evaluation stack— int32 , int64 , and native int.
除了通过托管指针类型之外,这没有提及值类型。然而
ldfld
的规范,例如,说:The ldfld instruction pushes onto the stack the value of a field of obj. obj shall be an object (type O), a managed pointer (type &), an unmanaged pointer (type native int), or an instance of a value type.
这是否意味着可以直接将值类型推送到计算堆栈上(而不是通过托管指针)?如果是这样,我是否可以假设被推送的值类型是原始值的成员副本(例如,字段值)?
最佳答案
参见对 III.1.1 的介绍(重点是我的):
While the CTS defines a rich type system and the CLS specifies a subset that can be used for language interoperability, the CLI itself deals with a much simpler set of types. These types include user-defined value types and a subset of the built-in types. The subset, collectively called the “basic CLI types”, contains the following types:
关于.net - CIL 评估堆栈可以包含值类型吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20151422/