为什么C#编译器发出的IL额外的操作码? [英] Why does C# compiler emit additional OpCodes in IL?
本文介绍了为什么C#编译器发出的IL额外的操作码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个方法乘
定义为:
If I've a method Multiply
defined as:
public static class Experiment
{
public static int Multiply(int a, int b)
{
return a * b;
}
}
那么为什么编译器发出此IL:
Then why does the compiler emit this IL:
.method public hidebysig static int32 Multiply(int32 a, int32 b) cil managed
{
.maxstack 2 //why is it not 16?
.locals init (
[0] int32 CS$1$0000) //what is this?
L_0000: nop //why this?
L_0001: ldarg.0
L_0002: ldarg.1
L_0003: mul
L_0004: stloc.0 //why this?
L_0005: br.s L_0007 //why this?
L_0007: ldloc.0 //why this?
L_0008: ret
}
正如你所看到的,它也包含了一些额外的操作码不道理给我的时候,其实我期待以下的IL:
As you can see, it also contains some additional OpCodes which don't make sense to me, when in fact I expect the following IL:
.method public hidebysig static int32 MyMethod(int32 a, int32 b) cil managed
{
.maxstack 16
L_0000: ldarg.0
L_0001: ldarg.1
L_0002: mul
L_0003: ret
}
这做同样的事情。
所以,问题是,为什么编译器发出额外的操作码的IL?
So the question is, why does the compiler emit additional OpCodes in IL?
我使用调试模式。
推荐答案
多数用于调试和放大器;支持断点;看到这里的答案:的为什么我的调试这些NOP指令建立?
Mostly for debugging & breakpoint support; See an answer here: Why are these nop instructions in my debug build?
这篇关于为什么C#编译器发出的IL额外的操作码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文