When annotations in Visual Studio also produce code ......

Source: Internet
Author: User

Today, we found a super crazy problem in vs2008. After testing, we found that the same problem exists in vs2010.

Reproduce the problem --

Create a "Win32 console application" in C ++ in vs2008ProgramAnd add references to the MFC class library.

Add a comment before the _ tmain function, and then write a few words in the main function.CodeAnd set the breakpoint for the entire code.

 

 

 

Finally, in debug mode, press F5 to run the command. The result is not stopped at the second breakpoint. Instead, it runs directly !!

After repeated tests-including deleting NCB files, restarting vs, and restarting the computer ...... I suddenly thought that the annotations mentioned in exceptional C ++ style may affect the code, for example, "//?". Will be converted to "\", and the second line of code becomes invalid !!

Is it because of the annotation problem? So after removing the comments before _ tmain (), the breakpoint function came back !!

 

The commented-out code will also affect program debugging !! To understand this problem, I next checked the generated assembly code-that is, when the program runs to the first breakpoint, the Disassembly window is called up,

It is clearly a good piece of annotation code, but Microsoft's vs compiler simply adds a bunch of code in it. I am now learning the compilation under Win32. I only know that EBP and ESP are used to pass parameters during function calls.

 

The target code is generated in the code that has been commented out, although it does not directly affect the program results (the execution is normal, the above program can normally output 1), but you cannot view the breakpoint during debugging. The most worrying thing is that you do not know when these redundant code will have a greater impact. In addition, it is found that modifying the content in the commented-out struct (for example, adding or removing declarations of several fields) will also affect code generation ......

It took me a few hours to find out the problem, and I was still in a bad mood, the result is that you do not dare to use the // style annotation in VC ++. (The above annotation is OK after/**/is commented out ), and tried other possible problems.

 

Finally, re-build the project, and all the code will be knocked up, and everything is OK. Original ~~ It turns out that the above annotated code was sent to me by a colleague via QQ !!!! The line feed in the QQ dialog box is different from the line feed code in Vs, so the code commented out above will affect the program ~~ Qq ~~

Related Article

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.