.net - CIL 评估堆栈可以包含值类型吗?

标签 .net clr cil value-type

我对值类型和 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/

相关文章:

c# - CIL 数据类型及其在 C# 中的等价物

c# - Filter Type.GetProperties(),其中 PropertyType.Name 位于列表中

.net - 在 Release模式下在 .NET 中调试

c# - Gridview DataSource 有行,但 GridView 没有

sql-server - SQL CLR 拆分 UDF 中的标识列

.net - .NET Core 中没有 AppDomain!为什么?

c# - C# 中不允许接口(interface)<动态> - 解决方法

c# - .net 反汇编器/反编译器

c# - 如何在RDL中使用自定义实用程序类?

c# - Thread.Sleep(0) 在 .NET Core 3.1 上没有按预期工作