Do you learn to debug the program? (turn)

zhaozj2021-02-16  83

Do you learn to debug the program? Newcomers inevitably encounter a variety of problems when writing code, some of which are more simple, in fact, many problems are not difficult to solve, some or even the consequences of carefulness, there is no such problem, the key is Do you want to learn how to adjust the schedule, encounter problems during program execution to solve the problem, let's simply talk about commonly commissioned methods:

First, the breakpoint, that is, let us perform half of the time to stop, then we look at if our defined variable value is correct, such as the coordinates of our characters, the location of the map, etc. Below the VC, you can easily make a breakpoint operation as long as you press F9. When you encounter a program unknown error, you can even use this method to detect where you are, and then make further error analysis. It is important to note that your program is best in debug mode, although you can make a breakpoint in Release mode, but after all, debugging information is less, it is not conducive to debugging.

Second, the information output is to execute, while outputting some information, of course, this information will see how you set it, use this method to understand the internal data change in the program, and then monitor whether the program is based on our expectations Execute it. There are many ways to output, such as: Building a log file, then simply output the debug information to the file; or through the Output window in the VC IDE environment, you can use OutputDebugstring ("...") The function is output.

Third, the exclusion method, you can't analyze where to make an error, you start comments, take a comment one with a function module, see which module out of the problem, and then continue deep refinement, although this method is very effective.

Common error: 1. Grammatical errors, this doesn't have to say, the procurator code keyword spell, see if there is no mistake in the syntax.

Second, the variable does not declare that new people often make such errors, a variable defined domain different from the domain, resulting in illegal calls of variables, this will not be difficult to resolve if the content of the file should be noticed.

Third, the joint effect, there are two codes to perform no problem alone, but it is easy to make mistakes together. If you encounter this situation, you have to check the global variables. Does the function have conflicts, pay attention, sometimes these mistakes are not It will be embodied in the process of compilation, but directly in the execution process, sometimes there will be false "normal".

Fourth, the effectiveness of variable value, many times we will think that the value of certain variables is for granted, but there are often some time, their value is not as much as we wish, establish a valid variable verification mechanism is very useful and necessary.

V. The reasonable algorithm, but unreasonable results, some algorithms look simple, so in the brain simulation program, it is actually that this is not the case, and the algorithm is removed step by step, and the result is output soon, so you can find you. Imagine different places.

Six, array offline, we know that arrays access to the corresponding location by subscript, if not paying attention, it is difficult to generate offline operations because the subscript exceeds the maximum value of the array you define, this error looks more difficult, or possibly Will this error, causing an error in other places.

7. The pointer overflows, this is a very easy question, including the master often there will be such a situation, and this error is very headache. It is often necessary to wait until the program is executed for a period of time to reflect an abnormality. Good code preparation habits It is important, this problem can only be deactivated by time to do it.

转载请注明原文地址:https://www.9cbs.com/read-10490.html

New Post(0)