In-depth analysis of C ++ code compilation and statement Sequence

Source: Internet
Author: User

What kind of C ++ code can be regarded as standardized and easy-to-understand? There will be countless arguments in the details. In fact, no matter what the style and habits are, good code has several common features: good naming, consistency, and comments,The following describes the C ++ code.

The debugging tag applies to preprocessing # define defines one or more debugging tags. In the code, use # ifdef and # endif for debugging management. After the program is finally debugged, you only need to use the # undef flag to debug the code. Common debugging labels are DEBUG and C ++ code statement sequences:

 
 
  1. # Include< Assert> 
  2.  
  3. Using namsapce std;
  4.  
  5. Int main ()
  6.  
  7. {
  8.  
  9. IntI=100;
  10.  
  11. Assert (I! = 100); // Fails
  12.  
  13. }
  14.  
  15. After debugging is complete, go to # include<Assert>Add # define NDEBUG to remove the code generated in red.
  16.  
  17. }

During running, the debug flag is enabled and disabled during running. You can set a debug bool flag. This is more convenient for the program running on the command line.

For example, the following C ++ code:

 
 
  1. #define DEBUG  
  2. #ifdef DEBUG  

The macro is in progress. When assert is used, a parameter is provided, that is, a true expression. The Preprocessor generates code to test the assertions. If the assertions are not true, an error message is sent to indicate what the assertions are and if they fail for a while, the program will terminate.

 
 
  1. # Include<Iostream> 
  2.  
  3. # Include<String> 
  4.  
  5. Using namespace std;
  6.  
  7. BoolDebug=False;
  8.  
  9. Int main (int argc, char * argv [])
  10.  
  11. {
  12.  
  13. For (intI=0; I<Argc; I ++)
  14.  
  15. If (string (argv [I]) ="-- Debug=On")
  16.  
  17. Debug=True;
  18.  
  19. BoolGo=True;
  20.  
  21. While (go)
  22.  
  23. {
  24.  
  25. If (debug)
  26.  
  27. {
  28.  
  29. Debug code
  30.  
  31. } Else {}
  32.  
  33. }
  34.  
  35. }

The above tutorials mainly introduce the good C ++ code style, How to Write secure code, and program debugging technology in the Visual C ++ environment, this content is important for new employees to grow from students to Real programmers, gradually participate in the development of actual projects, and read Third-Party code.

  1. How to better learn the C ++ Language
  2. Study how to adjust Visual C ++ language by ADO
  3. Detailed description of Visual C ++ programming Database
  4. Detailed usage and maintenance of the C ++ Library
  5. Two classification methods for analyzing the complexity of C ++

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.