Setup compiler options
For C , / zi, turn the compiler to PDB (Program Database). The PDB contains type information (type information) and symbol debug information (Symbolic DEBUGGING Information). Symbolic Debugging Information is about the name and type, function and its information in the code in the code. When compiled, we can set the IDE Switches and Command-Line options to debug. For example, in Visual C we can tell the compile to compile whether we allow the PDB to be generated by setting / zi. Similarly, / OD prohibits compiler optimization code. Although this will slow down the running speed of the code, this is very useful for debugging.
Set the picture (Project Property Pages èC / C ègeneral Propertyèdebug Information Format, set this option to / zi (PROGRABASE). Please do not set to Database for Edit & Continue, otherwise the compiler will join a lot of additional additional Editing and continuing information, and this information is very huge and will slow down the speed.
After setting the compilation option, we will set the connection option (Linker Switches): / incremental: no, / debug, and /pdb. (Project Property PageSèlinkerègeneral Propertyènge Incremental Linking)
(Project Property PageSèlinkerèdeBugging ProPERY) Sets the debug info option to Yes (/ debug). Let's set the / PDB option, set the Gennerate Program Database File option to $ (Outdir) / $ on / PDB option. Projectname) .pdb.
An Incrementally Linked Program is the same as nonincrementally linked. However, both INCREMENTALLY LINKED Executable (.exe) or Dynamic-Link Library (DLL) is ready for later connections, so: 1. An Incrementally Linked Program will be larger than Nonincrementally Linked Program, because it has added some extra code and data. 2. You may reposition the address of the FUNCTION
Note: In the final Release version, we don't need additional information, so use nonincrementally when connecting.
When we want to complete the symbol (Symbols) debug information, / opt: ref and / opt: ICF is required. (Linkerèoptimization Propertyèreference), set the compiler option to Eliminate Unreferenced Data (/ Opt: REF). Set Enable Comard Folding to REMOVE Redundant COMDATS (/ OPT: ICF). / Debug options as default options in Debug mode, this option Make the compiler to connect all functions (whether there is any call). / OPT: The REF option tells the connector only the function call used by the program. If you have forgotten setting / opt: ref, the RELEASE version of the program will contain a function you do not call, so that the program becomes large. / OPT: ICF will merge the determined data COMDAT record in the case of it. When you use constants, all references will point to this variable (not data redundancy). If we want to treat all Warning as an error, the / wx option will meet the requirements. The default warning level of Visual C is WARNING-Level 3 (the options corresponding in CL.exe are / W3). The next level of warning is WARNING-Level 4 (the corresponding option in Cl.exe is / W4), and we need to set the compiler to regard all Warning as Error (/ wx). (Project Property Pagesèc / C ègeneral property)
Set the warning level of the compiler to Warning-Level 4 and join / wx's ideas to be very good J. But in fact, this configuration will not want to be in the like. When we are compiling, we will feel confused. If we can't fix all Warning (no matter what), you will lose a lot of information hidden in the output, and we cannot debug the program in this case. So we have to treat WARNING very intuitive. #pragma Warning For us more applicable.
When you are in a header file, if you don't want the compiler to set the warning level to Warning-Level 4, # Pragma Warning can help us reduce the compiler's warning level: Before you contain the header file test.h, we Set the warning level of the compiler to 3 (#pragma Warning (PUSH, 3)), when we complete, resume the compilation level of 4 (#pragma Warning (POP)), so the next compilation compiler Warning-level 4 will be adopted.
#pragma Warning (Push, 3)
#include "test.h"
#pragma Warning (POP)
At the same time, we can also use #pragma Warning to disable displays a warning (#pragma Warning (Diable: 4201)). Then when we don't need it, we returns Warning to the default state (#pragma Warning (Default: 4201)).
// Disable a Individual Warning
#pragma Warning (Disable: 4201)
......
// Turn Warning Back on.
#pragma Warning (Default: 4201)
We often encounter a warning: C4100, "'Identifier': unreferenced formal parameter". When we encounter this situation, we often don't know how to do L. The solution is this: When you have another parameter (Parameter) is not used, the best way is to remove this parameter when it is defined. However, when you use the object-oriented method, you have to derive a member function without the change of the base class, and the member function does not need to use these parameters, then we can remove the parameters, but only Leave a parameter type method to implement. // this code will will generate the c4100 error.
INT Problemmethod (Int i, int J)
{
Return (5);
}
// The Following Code Properly Avoids The C4100 Error.
INT GoodMethod (int / * i * /, int / * j * /)
{
Return (22);
}