I accidentally understood the difference between release and debug.

Source: Internet
Author: User
Tags mscorlib

Before that, let me tell you the difference between the software compiled by release and Debug. I can only write a set of statements, without in-depth understanding and practical feelings. Recently, msil has encountered some mistakes when writing a piece of C # code. This is the mistake. Through msil, I learned the difference between the two from one aspect.

The source code is as follows:

 

Int x, y, z;
String S;

Console. writeline ("Enter X :");
S = console. Readline ();
X = int32.parse (s );

Console. writeline ("Enter Y :");
S = console. Readline ();
Y = int32.parse (s );

If (x <Y)
Z = X;
Else
Z = y;

Console. writeline ("{0: d}, Z ");

It is easy to see that, by mistake in the last line, I meant to output the value of Z. Because the quotation marks are incorrect, the output is: {0: d}, Z. In this case, if... else is useless.

The msil Code Compiled by debug is as follows:

. Method private hidebysig static void main (string [] ARGs) cel managed
...{
. Entrypoint
// Code size 80 (0x50)
. Maxstack 2
. Locals Init ([0] int32 X,
[1] int32 y,
[2] int32 Z,
[3] string s,
[4] bool CS $4 $0000)
Il_0000: NOP
Il_0001: ldstr "Enter X :"
Il_0006: Call void [mscorlib] system. Console: writeline (string)
Il_000b: NOP
Il_000c: Call string [mscorlib] system. Console: Readline ()
Il_0011: stloc.3
Il_0012: ldloc.3
Il_0013: Call int32 [mscorlib] system. int32: parse (string)
Il_0018: stloc.0
Il_0019: ldstr "Enter Y :"
Il_001e: Call void [mscorlib] system. Console: writeline (string)
Il_0023: NOP
Il_0024: Call string [mscorlib] system. Console: Readline ()
Il_0029: stloc.3
Il_002a: ldloc.3
Il_002b: Call int32 [mscorlib] system. int32: parse (string)
Il_0030: stloc.1
Il_0031: ldloc.0
Il_0032: ldloc.1
Il_0033: CLT
Il_0035: LDC. i4.0
Il_0036: CEQ
Il_0038: stloc. s CS $4 $0000
Il_003a: ldloc. s CS $4 $0000
Il_003c: brtrue. s il_0042
Il_003e: ldloc.0
Il_003f: stloc.2
Il_0040: Br. s il_0044
Il_0042: ldloc.1
Il_0043: stloc.2
Il_0044: ldstr "{0: d}, Z"
Il_0049: Call void [mscorlib] system. Console: writeline (string)
Il_004e: NOP
Il_004f: Ret
} // End of method program: Main

Release compilation is much simpler, and there is no NOP operation:

. Method private hidebysig static void main (string [] ARGs) cel managed
...{
. Entrypoint
// Code size 61 (0x3d)
. Maxstack 2
. Locals Init ([0] int32 X,
[1] int32 y,
[2] string S)
Il_0000: ldstr "Enter X :"
Il_0005: Call void [mscorlib] system. Console: writeline (string)
Il_000a: Call string [mscorlib] system. Console: Readline ()
Il_000f: stloc.2
Il_0010: ldloc.2
Il_0011: Call int32 [mscorlib] system. int32: parse (string)
Il_0016: stloc.0
Il_0017: ldstr "Enter Y :"
Il_001c: Call void [mscorlib] system. Console: writeline (string)
Il_0021: Call string [mscorlib] system. Console: Readline ()
Il_0026: stloc.2
Il_0027: ldloc.2
Il_0028: Call int32 [mscorlib] system. int32: parse (string)
Il_002d: stloc.1
Il_002e: ldloc.0
Il_002f: ldloc.1
Il_0030: Pop
Il_0031: Pop
Il_0032: ldstr "{0: d}, Z"
Il_0037: Call void [mscorlib] system. Console: writeline (string)
Il_003c: Ret
} // End of method program: Main

I started to use release for compilation. It seems strange that if... else does not compile a paragraph. I guess it's strange. Run the command and the result is "{0: d}, Z ". The last row of hand errors were found, which directly led to the spam code of IF... else. Then, use F11 to track the data in a single step. If... else, the Code simply skips the whole step. So I changed the debug mode for compilation and found that the compiled msil if... else is complete, and the single-step tracking is followed up. Suddenly realized...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.