在生成的 IL 代码中,缺少一些行。 in between 行执行什么任务?
In the IL code produced, there are some lines missing. What task does the in between lines perform?
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 9 (0x9)
.maxstack 1
.locals init ([0] class ConstReadOnly.second p)
IL_0000: nop
IL_0001: ldc.i4.5
IL_0002: newobj instance void ConstReadOnly.second::.ctor(int32)
IL_0007: stloc.0
IL_0008: ret
} // end of method Program::Main
此处 IL_0002
后跟 IL_0007
。
任何人都可以告诉我这里发生的实际情况吗?
这只是标签。中间没有代码。标签表示从函数开始的偏移量(以字节为单位)。
offset_0: nop //size 1 byte
offset_1: ldc.i4.5 // size 1 byte
offset_2: newobj instance void ConstReadOnly.second::.ctor(int32) // size 5 bytes
offset_7: stloc.0 // size 1 byte
offset_8: ret
您可以轻松更改它们并重新编译。
当我在你的代码上 运行 ildasm
指定 /BYTES
选项时,输出是:
.method private hidebysig static void Main(string[] args) cil managed
// SIG: 00 01 01 1D 0E
{
.entrypoint
// Method begins at RVA 0x2048
// Code size 9 (0x9)
.maxstack 1
.locals init (class ConstReadOnly.second V_0)
IL_0000: /* 00 | */ nop
IL_0001: /* 1B | */ ldc.i4.5
IL_0002: /* 73 | (06)000003 */ newobj instance void ConstReadOnly.second::.ctor(int32)
IL_0007: /* 0A | */ stloc.0
IL_0008: /* 2A | */ ret
} // end of method Program::Main
在这里您可以看到用于在磁盘上表示您的代码的实际字节数作为注释。请注意,所有指令仅使用一个字节,但 newobj
指令除外,它是 5 个字节,与行标签中使用的数字完全对应。
那些标签在那里,以便任何跳转指令都可以向您显示它们跳转的位置。它们与您在 C# 中编写的代码行没有任何关系。
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 9 (0x9)
.maxstack 1
.locals init ([0] class ConstReadOnly.second p)
IL_0000: nop
IL_0001: ldc.i4.5
IL_0002: newobj instance void ConstReadOnly.second::.ctor(int32)
IL_0007: stloc.0
IL_0008: ret
} // end of method Program::Main
此处 IL_0002
后跟 IL_0007
。
任何人都可以告诉我这里发生的实际情况吗?
这只是标签。中间没有代码。标签表示从函数开始的偏移量(以字节为单位)。
offset_0: nop //size 1 byte
offset_1: ldc.i4.5 // size 1 byte
offset_2: newobj instance void ConstReadOnly.second::.ctor(int32) // size 5 bytes
offset_7: stloc.0 // size 1 byte
offset_8: ret
您可以轻松更改它们并重新编译。
当我在你的代码上 运行 ildasm
指定 /BYTES
选项时,输出是:
.method private hidebysig static void Main(string[] args) cil managed
// SIG: 00 01 01 1D 0E
{
.entrypoint
// Method begins at RVA 0x2048
// Code size 9 (0x9)
.maxstack 1
.locals init (class ConstReadOnly.second V_0)
IL_0000: /* 00 | */ nop
IL_0001: /* 1B | */ ldc.i4.5
IL_0002: /* 73 | (06)000003 */ newobj instance void ConstReadOnly.second::.ctor(int32)
IL_0007: /* 0A | */ stloc.0
IL_0008: /* 2A | */ ret
} // end of method Program::Main
在这里您可以看到用于在磁盘上表示您的代码的实际字节数作为注释。请注意,所有指令仅使用一个字节,但 newobj
指令除外,它是 5 个字节,与行标签中使用的数字完全对应。
那些标签在那里,以便任何跳转指令都可以向您显示它们跳转的位置。它们与您在 C# 中编写的代码行没有任何关系。