为什么 C# ->CIL 在每条指令上都有标签吗? [英] Why does C# -> CIL have a label on every instruction?

查看:19
本文介绍了为什么 C# ->CIL 在每条指令上都有标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编译的 C# 程序上使用 ILDASM.exe 时,它​​显示方法中的每条指令都有一个标签.

When using ILDASM.exe on a compiled C# program, it shows that there is a label for every instruction within methods.

例如:

IL_0001:  ldc.i4.4
IL_0002:  stloc.0
IL_0003:  ldc.r8     12.34
IL_000c:  stloc.1
IL_000d:  ldc.r8     3.1415926535897931
IL_0016:  stloc.2
IL_0017:  ldstr      "Ehsan"
IL_001c:  stloc.3
IL_001d:  ret

这是为什么?这样做是不是效率低下,还是 CIL 编译器会自己优化这些标签?

Why is this? Is it not inefficient to do this or does the CIL compiler optimize these labels itself?

推荐答案

标签不存在于编译的 CIL 中.为方便起见,它们显示在反汇编代码中.

Labels are not present in the compiled CIL. They are displayed for your convenience in the dissassembled code.

这些特定的标签对应于指令偏移量,而手工代码没有这种限制(标签可以是任意字符串).

These particular labels correspond to instruction offsets, while there is no such restriction on hand-made code (labels could be arbitrary strings).

这篇关于为什么 C# ->CIL 在每条指令上都有标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆