C ++ is an abnormal change in the data codes

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_33810188/article/details/82632205

In a recent case before writing the code, suddenly found in the data structure is no sign (without human assignment changes) of changes, check for a long time, and let checked for a long time, have not been found question, I feel very strange!

Finally, I decided to run the entire code again, step by step debugging, finally found the problem, turned out to be an argument took place when cross-border stored data! Coincidentally, the occurrence of cross-border place, just place the structure to store data! Cause the data structure of reason to be changed!

The basic error of the whole process can describe the following forms:

First, define the parameters,

typedef struct ST

{

int x;

int y;

}st;

st struc;

struc.x=10;

struc.y=10;

int a[10]={0};

In the data processing,

a [20] = 12; // occurred bounds!

It happens is exactly the place where cross-border struc opened up the memory, resulting in data struc changed!

-------------------------------

to sum up:

Before, has not been found to this problem is generally not very good because the cross-border occurred, even if there is no occurrence ran into the parameters defined in the previous, so the bug has been hidden down!

All in all, in the use of data, be sure to pay attention to memory! Even if not manually open up memory space, but also pay attention to other forms of cross-border data! This results in the problem of difficult to detect, even if found, not very good at programming, it is difficult to find root of the problem (in particular, the amount of code very great time!).

 

 

Guess you like

Origin blog.csdn.net/qq_33810188/article/details/82632205