"auto," "ansi," 和 "cil managed" 在 CIL 中做什么?

What do "auto," "ansi," and "cil managed" do in CIL?

出于各种原因我正在学习 CIL,似乎 类 的定义通常类似于:

 .class public auto ansi beforefieldinit [...] extends [mscorlib]System.Object

函数定义为:

 .method [...] (args) cil managed

我明白其他一切,但我似乎无法找出 "auto" 或 "ansi" 或 "cil managed" 的作用。关键字也太模糊了,我无法获得具体的搜索结果(beforefieldinit 几乎立即出现)。

来自 ECMA CLI:

ansi 将字符串作为 ANSI 编组到平台。 §II.10.1.5

auto 自动提供字段布局。 §II.10.1.2

beforefieldinit 静态方法前不需要初始化类型 叫。 §II.10.1.6

关于'cil managed',该方法属性说明该方法包含IL,其所有代码都是托管的。

ECMA-335 提供您寻找的信息,

II.10.1 Type header(ClassHeader)下你会发现:

auto - Layout of fields is provided automatically. - §II.10.1.2

ansi - Marshal strings to platform as ANSI. - §II.10.1.5

Serge Lidin,在他的书 .Net IL Assembler 中第 1 章 Class 声明中写道:

The keyword auto in this context defines the class layout style (automatic, the default), directing the loader to lay out this class however it sees fit. Alternatives are sequential (which preserves the specified sequence of the fields) and explicit (which explicitly specifies the offset for each field, giving the loader exact instructions for laying out the class). The keyword ansi defines the mode of string conversion within the class when interoperating with the unmanaged code. This keyword, the default, specifies that the strings will be converted to and from “normal” C-style strings of bytes. Alternative keywords are unicode (strings are converted to and from UTF-16 Unicode) and autochar (the underlying platform determines the mode of string conversion).


II.23.1.11 方法标志 [MethodImplAttributes] 下,您可以阅读:

IL - 0x0000 - Method impl is CIL

Managed - 0x0000 - Method impl is managed

Serge Lidin,在第 1 章的方法声明下对此进行了描述:

The keywords cil and managed define so-called implementation flags of the MethodDef and indicate that the method body is represented in IL. A method represented in native code rather than in IL would carry the implementation flags native unmanaged.


我建议你买一本关于这个主题的书,我认为有几本。它比在 ECMA-335 规范中挖掘要快得多。