G
Guest
I've got a simple console app which just assigns 6 to an int and prints out
the value. The IL looks like:
..method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
// Code size 12 (0xc)
.maxstack 1
.locals init ([0] int32 x)
IL_0000: nop
IL_0001: ldc.i4.6
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: call void [mscorlib]System.Console::Write(int32)
IL_0009: nop
IL_000a: nop
IL_000b: ret
} // end of method Module1::Main
What is the point of these:
IL_0002: stloc.0
IL_0003: ldloc.0
Why store something in a variable just to put the exact thing right back on
the stack where it was? The proper value was on the stack before that anway,
right? Couldn't these two lines be taken out?
-Ben
the value. The IL looks like:
..method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01
00 00 00 )
// Code size 12 (0xc)
.maxstack 1
.locals init ([0] int32 x)
IL_0000: nop
IL_0001: ldc.i4.6
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: call void [mscorlib]System.Console::Write(int32)
IL_0009: nop
IL_000a: nop
IL_000b: ret
} // end of method Module1::Main
What is the point of these:
IL_0002: stloc.0
IL_0003: ldloc.0
Why store something in a variable just to put the exact thing right back on
the stack where it was? The proper value was on the stack before that anway,
right? Couldn't these two lines be taken out?
-Ben