Everyone may have been using
VC
Developing software, but it is not a matter of understanding for this compiler. There are many reasons. In most cases, we only stay in "use" it, and not to "understand" it. Because it is just a tool, we would rather put more energy in
C
Language and software design. We are accustomed to such a "model": establish a project, then write code, then compile, repeat the debugging. However, the so-called: "Experience in a good thing, must first make a tool". If we are fine
VC
Development environment, can we do more?
Gossip less. Let's first take a look at the process of VC and is roughly divided into two steps: compilation and connection. The source file generates the .Obj file by compiling; all .Obj files and .lib files generate a .exe file or .dll file. Below, we discuss some details of these two steps.
Compile parameters set. Mainly through the VC's menu item Project-> settings-> C / C page is completed. We can see the content of this page of the bottom Project Options, generally as follows:
/ NOLOGO / MDD / W3 / GM / GX / ZI / OD / D "WIN32" / D "_debug" / d "_windows" / d "_afxdll" / d "_mbCS" /fp"debug/writingdlgtest.pch "/ yu "stdafx.h" / fo "debug /" / fd "debug /" / fd / gz / c
The meaning of each parameter represents, you can refer to MSDN. For example, / NOLOGO indicates that the output window is not displayed in the output window (we can remove this parameter to look at the effect), etc.. Generally we do not directly modify these settings, but through the top Category in this page.
1) General: Some overall settings. WARNING LEVEL is used to control the warning message, where Level 1 is the most serious level; Warnings as Errors will be warned as an error handling; Optimizations are code optimization, and you can make a thinner setting in the category's Optimizations; Generate Browse INFO To generate .sbr file, record class, variable, etc., you can make more settings in Category's Listing Files item. Debug Info, generate debugging information: None, does not generate any debug information (comparative faster); line number only generates debugging information of global and external symbols to .Obj file or .exe file, reduce the size of the target file; C 7.0-compatible, record all symbol information used by the debugger to the .obj file and .exe file; Program Database, create a .pdb file to record all debugging information; Program Database for "Edit & Continue", create a .pdb file record all debugging Information, and support the debugging.
2) C Language: Pointer_to_member representation Used to set the relationship of class definitions / references, generally Best-Case Always indicates that this class is defined before the reference class; Enable Exception Handling, synchronized exception handling; Enable Run-Time TYPE INFORMATION Forces the compiler to increase the code to perform object type check at runtime; Disable Construction Displacements, setting the class construction / destructor calling virtual function problem. 3) Code Generation: Processor Represents code instruction optimization, can be 80386, 80486, Pentium, Pentium Pro, or Blend represents various optimizations. Use Run-Time Library is used to specify the runtime library used by the program runtime (single thread or multi-thread, Debug version or Release version), there is a principle that one process does not use several versions of the runtime library. Single-Threaded, LIBC.LIB static link library; Debug Single-Threaded, LIBCD.LIB static link library; Multithreaded, LIBCMT.LIB static link library; Debug Multithreaded, LIBCMTD.LIB static link library; Multithreaded DLL, dynamic link MSVCRT.DLL The library; Debug Multithreaded DLL, dynamically connect the MSvcrtd.dll library. Connecting a single-line library does not support multi-threaded calls, connecting multi-thread libraries requires creating multi-threaded applications. Calling convention can be used to set the call convention, there are three types: __ cdecl, __ fastcall and __stdcall. The main difference between various calls is that the function is called, the parameter of the function is pressed from left to right or from right to left. When the function returns, the caller is cleaned into the stack. Still cleaning by the function itself; and naming modifications to the function name at compile time (you can see various named modifications via Listing Files). Struct Member Alignment is used to specify the member variables in the data structure in memory, and the speed of alignment data is different depending on the number of bits of the computer data bus. This parameter is especially important for applications such as packet network transmission, not access speed issues, but the accurate definition of data bits, generally using #pragma packs in the program.
4) Customize: Disable language Extensions, indicating that the language extension does not use Microsoft to standard C; Eliminate Duplicate Strings is mainly used for string optimization (put the string into the slow pool to save space), use this parameter, make
Char * sbuffer = "this is a character buffer";
Char * TBuffer = "this is a character buffer";
SBuffer and TBuffer points to the same memory space; Enable Function-Level Linking, tell the compiler to compile each function in package format; Enables Minimal Rebuild, by saving the associated information to the .IDB file, so that the compiler is only modified to the latest class The source file is recompiled, increasing compilation speed; Enable Incremental Compilation, the same information saved by .IDB file, only recompile the latest modified functions; Suppress Startup Banner and Information Messages, to control whether the parameters are output in Output window . 5) Listing Files: The feature of Generate Browse Info has been mentioned above. Here you can make more settings. Exclude local variables from breakse info indicates whether the information of the local variable is placed in the .sbr file. Listing File Type can set the content of the generated list information file: assembly-only listing only generates a compilet code file (.asm extension); Assembly With Machine Code generates machine code and assembly code file (.cod extension); askEMBLY with SOURCE Code generates source code and assembly code files (.asm extension); assembly, machine code, and source generates machine code, source code, and assembly code files (.cod extensions). Listing file name is the path to the generated information file, generally to automatically pick up the file name of the source file in the debug or release directory.
6) Optimizations: Code Optimization Settings. You can select Maximize Speed to generate the fastest code, or the minimize size generates a minimum size program, or Customize custom optimization. Customized contents include:
Assume no aliasing, not using alias (increase speed);
Assumesing Across Function Calls, only the alias is not used inside the function;
Global Optimizations, global optimization, such as frequently used variables to save, or calculated within the loop, such as
i = -100;
While (i <0) {i = x y;
Will be optimized
i = -100;
T = x y;
While (i <0) {i = t;
Generate Intrinsic functions, replace some function calls (increase speed) using internal functions;
Improve float consistency, optimization of floating point operations;
Favor Small Code, Program (EXE or DLL) Size Optimization takes precedence over code speed optimization;
Favor Fast Code, Program (EXE or DLL) code speed optimization is preferred for dimensional optimization;
Frame-Pointer OMIMission, does not use frame pointer to increase function call speed;
Full Optimization combines several parameters to generate the fastest program code. Inline function expansion, inline function extension three optimization (using inline can save functions, speed up the program speed): Disable does not use inline; only __inline, only the function definition has inline or __inline mark before using inline Any suitable, in addition to the INLINE or __INLINE tag, the compiler "I think" I should use the inline function, all inline.
7) Precompiled Headers: The settings for the precompiled head file. Use pre-compilation to improve the speed of repeated compilation. VC typically places some public, uncommon headers (such as AfxWin.h, etc.) in Stdafx.h, this part of the code does not have to recompile each time (unless it is Rebuild All).
8) Preprocessor: Pre-compiled processing. You can define / unwind some constants. Additional Include Directories, you can specify additional directorys, usually relative to the directory of this item, such as ../include.
Connection parameters set. Mainly through the VC's menu item Project-> settings-> link page. We can see the content of this page of the bottom Project Options, generally as follows:
/ NOLOGO / SUBSYSTEM: Windows / Incremental: Yes /PDB: "Debug/writingdlgtest.pdb" / debug / machine: i386 /out:"debug/writingdlgtest.exe "/ pdbtype: sept
Let's take a look at the settings in category.
1) General: Some overall settings. You can set the generated file path, file name; connected library file; Generate Debug INFO, generate debug information to .pdb files (set in category-> debug); Ignore All Default Libraries, Abandon all default library connections Link Incrementally, through the generated. ILK file implements incrementally connected connections to increase the subsequent connection speed, but generally generated files (EXE or DLL) generated in this manner; Generate MapFile, generate .MAP file record module related information; Enable Profiling This parameter is usually used simultaneously with the generate mapfile parameter, and if DEBUG information is generated, it cannot be used with .pdb files, and must use Microsoft Format.
2) Customize: This can be used to use the program database file. Force File Output, forcing the output file (EXE or DLL); Print Progress Messages can output progress information during the connection to the Output window.
3) Debug: Set whether to generate debugging information, and debug information format. Formats can have three options for Microsoft Format, Coff Format (Common Object File Format) and Both Formats; Separate Types, indicating that DEBUG format information is stored in separate .pdb files, or placed directly in the.pdb file of each source file. In the case, it means that the latter is used, which is fast to debug startup. 4) INPUT: Here you can specify the library file to be connected to abandon the library files. You can also add additional library file catalogs, usually relative to the directory of this item, such as ../lib. Force Symbol References, you can specify a library that connects specific symbol definitions.
5) Output: Base Address can change the program default base address (EXE file defaults to 0x400000, DLL default is 0x10000000), always try to start from this base address when the operating system is loaded. Entry-Point Symbol Specifies the entry address of the program, typically a function name (and must use the __stdcall call convention). General Win32 program, EXE's entrance is WinMain, the entry of the DLL is DLLLENTRYPOINT; it is best to let the connector automatically set the program's entry point. By default, through a C runtime library function: The console program uses MainCrtStartup (or WMAINCRTSTARTUP) to call the program's main (or wmain) function; Windows program uses WinMainCrtStartup (or wwinmaincrtstartup) calls to Winmain (or wwinmain) The __stdcall call convention must be used); the DLL uses the _dllmaincrtstartup calls the DLLMAIN function (must adopt the __stddcall call convention). Stack Allocations, used to set the stack size used by the program (please use the decimal), the default is 1 megabyte. Version Information tells the connector to put the version number on the beginning of the EXE or DLL file.
It is worth noting that the above parameters are sensitive; when the parameter is added "-" indicates that the parameter is invalid; each parameter value option has the default value of "*" is the default value of this parameter; you can use the top right corner "Reset" button to restore all the default settings for this page.
Other parameter settings.
1) Project-> settings-> general, you can set the way to connect the MFC library (static or dynamic). If it is a dynamic connection, don't forget the DLL of the MFC when you are published.
2) Project-> settings-> debug, you can set the executable running time when debugging, and the command line parameters, etc.
3) Project-> Settings-> Custom Build, you can automate some operations after the compilation / connection is successful. More useful is that when writing COM, I hope that VC is automatically registered with the compilation COM file, which can be set as follows:
Description: Register COM
Commands: Regsvr32 / S / C $ (TargetPath)
Echo Regsvr32 Exe.Time> $ (Targetdir) / $ (Targetname) .TRG
Outputs: $ (targetdir) / $ (targetname) .trg4) Tools-> Options-> Directories, setting the system's include, library path.
Some tips
1) Sometimes, when you can compile, the computer suddenly illegally shuts down (maybe someone accidentally touches the power or your memory instability.). When you restart the machine, open the project, re-compile it, and find that the VC will collapse. You may think that your VC compiler is broken, it is not (you try to compile other projects, or good!), You only need to put the project's .ncb, .opt, .aps, .clw file and debug, release directory All files are deleted and then recompiled.
2) If you want to share your source code project with others, it is too big to copy the entire project. You can delete the following files: .dsw, .ncb, .opt, .aps, .clw, plg file, and debug, all files in the release directory.
3) When you contain multiple project in your workspace, you may not be intuitive, which one is the current project. You can set it as follows: Tools-> Options-> Format, then select Workspace Window in Category to change its default font (such as Fixedsys).
4) How to change the existing Project? Turn it off. Then open the .dsp file in the text format, replace the original Project name.
5) VC6 is useful for the smart prompt function of class members, but sometimes it will fail. You can turn off the project first, remove .clw and .ncb, then reopen the project, click on the menu item View-> ClassWizard, press "Add All" button in the pop-up dialog; re-rebuild all. You should be able to solve the problem.