Second, in which case the release version will be wrong
With the introduction above, let's take a look at each of these options to see how the release version of the error was generated.
1. Runtime Library:
2. Optimization: This type of error mainly includes the following types:
(1) Frame pointer (frame Pointer) ellipsis (abbreviated to FPO): All call information during function call
(return address, parameters) and automatic variables are all placed on the stack. If the Declaration and implementation of the function are different (parameters, return
return value, call mode), will produce an error ———— but in the Debug mode, the stack is accessed via the EBP register
Saved address implementations, if there are no errors such as array out of bounds (or "not many"), the function can usually
normal execution; In Release mode, optimizations omit the EBP stack base pointer, which accesses the stack through a global pointer
It causes the return address error to be a program crash. The strong-typing nature of C + + can check out most of these errors, but
If a forced type conversion is used, it is not. You can force the/oy-compilation option to off in release release
The drop frame pointer is omitted to determine if this type of error.
(2) Volatile variable: volatile tells the compiler that the variable may be modified in an unknown way outside of the program
(such as systems, other processes, and threads).
(3) Variable optimization: The optimizer optimizes variables based on the use of variables. For example, there is a function that has not been
The variable used, in the Debug version it is possible to hide an array out of bounds, and in release version, this variable
is likely to be tuned, when the array is out of bounds and destroys useful data from the stack. Of course, the actual situation would be more complicated than this.
Many. Errors related to this are:
3. _DEBUG and Ndebug: When _DEBUG is defined, the Assert () function is compiled, and Ndebug does not
Be compiled. In addition, VC + + also has a series of assertion macros. This includes:
ANSI C asserts void assert (int expression);
C Runtime Lib asserts _assert (booleanexpression);
_asserte (booleanexpression);
MFC asserts assert (booleanexpression);
VERIFY (booleanexpression);
Assert_valid (Pobject);
Assert_kindof (classname, pobject);
ATL asserts Atlassert (booleanexpression);
In addition, the compilation of TRACE () macros is also controlled by _DEBUG.
4./GZ option: This option will do the following things
(1) Initialize memory and variables.
(2) When a function is called through a function pointer, the matching of the function call is verified by checking the stack pointer. (Prevent the original
Shape does not match)
(3) Check the stack pointer before the function returns, confirming that it has not been modified.
Third, how to "Debug" release version of the program
1. As mentioned earlier, Debug and Release are just a set of differences in compilation options, and there is actually nothing
The definition can differentiate between the two. We can modify the release version's compilation options to narrow down the error range. As described above, you can
Change the option of Release one by one to the opposite Debug option, such as/MD to/MDd,/o1 to/od
, or run time optimization to program size optimization. Note that only one option is changed at a time to see which option is wrong
The error that should be related to the option, and then locate it accordingly. These options are project\settings ... Can be used in both
To be selected directly from the list, usually not manually modified. Since the above analysis is quite comprehensive, this method is the most
and effective.
2. You can also debug your release version like Debug, just add debug symbols. In project/s
Ettings ... , select Settings for "Win32 Release", select the C + + label, Category Select
General,debug Info selected program Database. Again in the Link tab Project options finally
Add "/opt:ref" (do not lose the quotation marks).
Poptest Lao Li Talk about the difference between Debug and release (C #) 2