At the end of the program run, VC + + 6.0 If such a dialog box appears
is to trigger the debug error:damage before/after normal block.
If the compiler reports such a mistake, it is almost certainly in the program that the array accesses the bounds. For example:
int main ()
{
int *p=new int[5];
p[-1]=3;
delete [] p;
return 0;
}
When you execute to the DELETE statement, the above dialog box pops up, reporting damage before normal block
If the program is modified like this
int main ()
{
int *p=new int[5];
p[5]=3;
delete [] p;
return 0;
}
When you execute to the DELETE statement, you report an error damage after the normal block.
What is normal block? When you use the new operator to request memory space for a pointer, the memory space that the VC compiler assigns to the pointer is normal block. The initial value of each byte in this memory space is CD H. And put the memory space before 4 bytes and then 4 bytes
The initial value of the assignment is FDFDFDFD H.
The VC memory tool makes it easy to see the contents of this newly allocated memory space. As above two programs, VC for pointer p to request the memory space address from 0x00032f48 start. Use memory to view the content near this address, which is what the following figure shows:
When the memory space is freed with delete, the compiler checks that the 4-byte contents and the 4-byte contents of the memory are changed before that segment. If so, report damage before normal block and damage after normal block respectively.
However, the VC compiler of this error-checking function is very limited to prevent array access out of bounds, mainly relying on the programmer to be careful. As above the
In a program, the compiler cannot detect such an error if you let p[-2]=3, that is, change the memory before the memory address 0x00032f44. Similarly, P[6] is assigned a value, or will be P[5]=0XFDFDFDFD, the compiler will not error.