簡體   English   中英

IL代碼將Int16加載為Int32

[英]IL code loads Int16 as Int32

以下C#代碼:

short first = 1;
short second = 2;
bool eq1 = (first.Equals(second));

該代碼轉換為:

IL_0001:  ldc.i4.1    
IL_0002:  stloc.0     // first
IL_0003:  ldc.i4.2    
IL_0004:  stloc.1     // second
IL_0005:  ldloca.s    00 // first
IL_0007:  ldloc.1     // second
IL_0008:  call        System.Int16.Equals
IL_000D:  stloc.2     // eq1

ldloca.s 00 - 使用索引indx,short form加載局部變量的地址。

ldloc.1 - 將局部變量1加載到堆棧上。

為什么兩個命令都不是ldloca.s ,(兩個變量都是short型)?

值類型的所有實例方法都有一個類型為ref T的隱式this參數,而不是類型T ,這就是你的first變量需要ldloca的原因。 但是System.Int16.Equals的參數是System.Int16類型,沒有任何ref ,所以你的second變量不需要(並且不能傳遞) ldloca

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM