Windows program debugging ___ compile C ++ code for debugging (chapter 2)

Source: Internet
Author: User

Today, I read the <windows program debugging> C ++ code for debugging, it is of guiding significance to my own programming style and programming habits. note:

 

I. Design:

An important feature isSimplicityAndCouplingMost common design errors come from the complex components that are not necessary for programming. Therefore, make the program as simple and reasonable as possible. coupling is used to measure the degree of dependency between different objects, so the objects in the program should be as independent as possible.

 

II. C ++ programming style

1. Clearly write the code and express your meaning most directly;

2. Well-Structured code has a more useful call stack, which gives you more information;

3. Use a good logo name;

4. rethink of the Hungarian naming law, although this method was useful in the past, as the times have changed, the procedures written by the Hungarian naming law are hard to read, difficult to maintain, and easy to be misunderstood; (question: currently, most programmers still use this naming method. Is there a better and more reasonable way? I haven't introduced it in this book. Maybe the key is my habits)

5. Use simple statements;

6. Use a unified arrangement and a space key instead of the tab key;

7. Use parentheses to make the writing clearer. If you are not sure whether you need to use parentheses, you need to use parentheses to make the priority issue clear;

8. write comments for future maintenance.

 

III. C ++ Language

1. Select the C ++ language instead of the C preprocessing, but you need to use the pre-processor to understand the debugging code;

2. Declare all shared external symbols in the header file and retain the parameter names in the function prototype;

3. Remember to initialize data members in the constructor,

4. Check the bit mask value for unfamiliar bit masks. If necessary, use the mask macro or subdomain mask;

5. boolean expressions should check whether the expression is false rather than true;

For example, if (boolleanvalue = true)...; is unreasonable and should be changed to If (boolleanvalue! = False) ......; or If (boolleanvalue )....;

6. integer, numeric, and floating-point variables should be prevented from being deleted by one. Division by zero may cause overflow errors.

7. When using pointers and handles, the pointer should be reinitialized when the object indicated by the pointer is recycled, and it should be processed if it is null before the pointer is released;

8. do not rush to use forced type conversion, because forced type conversion will cause problems during maintenance. If you use dynamic_cast in Visual C ++, remember to select the Enable run_time type information option in the project settings;

9. using const carefully in a program is a good method to help the compiler find errors during compilation. However, it is very troublesome to add const if it is not used at the beginning. the use of const is a problem that does not move, and changes the whole body as soon as one moves;

10. If the addition operation of the loop variable must be executed during each loop, use the for statement instead of the while statement;

 

Iv. Visual C ++ Compiler

1. Try to use the compile-time check instead of the run-time check. It is a good way to use the W4 warning level;

2. the GZ compilation option is always used in the debugging version;

3. The "Compilation without warning" rule is very helpful for large program development teams, but the premise is that exceptions are allowed, and the final goal is to eliminate errors rather than warnings.

 

 

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.