Deep understanding of VC + + compilers

Source: Internet
Author: User
Tags class definition error handling exception handling

You may have been using VC development software, but for this compiler is not necessarily very understanding. The reasons are manifold. In most cases, we only stay in the "use" of it, and do not want to "understand" it. Because it's just a tool, we'd rather focus more on C + + language and software design. We are accustomed to such a "pattern": Create a project, and then write code, and then compile, debugging repeatedly. But, the so-called: "The public wants good, its prerequisite". If we are proficient in VC development environment, we can do more easily?

Gossip is less to say. Let's take a look at the VC processing process, roughly divided into two steps: compilation and connection. The source file is generated by compilation. obj file; Obj file and. Lib files are generated by connection. EXE file or. DLL file. Below, we discuss some of the details of these two steps separately.

The settings for the compilation parameters. Mainly through the VC menu item project->settings->c/c++ page to complete. We can see the contents of the following project options in this page, generally as follows:

/NOLOGO/MDD/W3/GM/GX/ZI/OD/D "WIN32"/d "_DEBUG"/d "_windows"/d "_afxdll" D "_m BCS"/fp "debug/writingdlgtest.pc H "/yu" stdafx.h "/fo" debug/"/fd" debug/"/fd/gz/c"

Each parameter represents the meaning of the MSDN. For example,/nologo indicates that these settings are not displayed in the Output window at compile time (we can remove this parameter to see the effect) and so on. Generally we do not modify these settings directly, but through the category in the top of the page.

1 General: Some overall settings. The Warning level is used to control warning messages, in which levels 1 is the most serious; warnings as errors treats warning messages as error handling; Optimizations is code optimization, A finer setting can be made in the optimizations item of the category; Generate browse info is used to generate. SBR files, record classes, variables, and other symbolic information, you can do more in the category listing files in the settings. Debug info, generate Debug Info: None, no debug information generated (faster compilation); line Numbers only, generates debug information for global and external symbols only. Obj file or. EXE file, reduce the size of the target file, C 7.0-compatible, record all the symbol information to the debugger. Obj file and. EXE file, program Database, create. PDB Files record all debugging information, program Database for "Edit & Continue", create. The PDB file records all debugging information and is editable when debugging.

2 C + + Language:pointer_to_member representation is used to set the sequence of class definitions/references, generally best-case always means that the class must have been defined before referencing the class; Enable Exception handling, synchronous exception handling; Enable run-time Type Information force the compiler to increase the code at run time for object type checking; Disable construction Displacements, set class constructor/destructor call virtual function problem.

3 The code generation:processor represents the optimization of codes instructions, which can be 80386, 80486, Pentium, Pentium Pro, or blend to indicate a mixture of the above optimizations. The Use Run-time library specifies the Run-time library (single-threaded or multi-threaded, debug version, or release version) used by the program at run time, and there is a principle that a process should not use several versions of the runtime library at the same time. single-threaded, static connection LIBC.LIB library; debug single-threaded, static connection LIBCD.LIB library; multithreaded, static connection LIBCMT.LIB library; debug multithreaded, static connection LIBCMTD.LIB library, multithreaded dll, dynamic connection MSVCRT.DLL Library, Debug multithreaded DLL, dynamic connection MSVCRTD.DLL library. Threaded calls are not supported on a single threading connection, and multiple-line threading are required to create multi-threaded applications.

Calling convention can be used to set calling conventions, there are three kinds: __cdecl, __fastcall and __ StdCall. The main difference between the various calling conventions is that when a function is called, the parameter of the function is pressed from left to right onto the stack or from right to left; When the function returns, the caller of the function cleans up the parameters of the indentation stack or the function itself, and the name modification of the function name at compile time (you can pass the listing files See various naming decorations. The Struct member alignment is used to specify that the membership variable in the data structure is aligned in bytes in memory, depending on the number of digits of the computer's data bus, different alignment accesses the data differently. This parameter is especially important for the application of packet network transmission, not the access speed problem, but the exact definition of data bits, which is usually specified by using #pragma pack in the program.

4) customize:disable Language Extensions, which means that Microsoft does not use the language extensions for standard C; Eliminate Duplicate Strings, which is mainly used for string optimization (putting strings into a slow-charging Chili to save space), Use this parameter to make

Char *sbuffer = "This is a character buffer";

Char *tbuffer = "This is a character buffer";

Sbuffer and Tbuffer point to the same memory space, Enable function-level linking, tell the compiler to compile the functions in packaged format; enables minimal rebuild, by saving the associated information to. IDB file, so that the compiler only the latest class definition changed source files to recompile, improve the compilation speed; Enable incremental compilation, the same pass. IDB file to save the information, only recompile the most recently modified functions, suppress Startup Banner and information Messages to control whether the parameter is Output window.

5) The function of Listing files:generate Browse info has been mentioned above. More settings can be made here. Exclude the local Variables from Browse info indicates whether to place the information for the locals. SBR file. The Listing file type can set the contents of the generated list information file: Assembly-only Listing only generate assembly code files (. ASM extension); Assembly with Machine code generates the machine code and assembly codes file (. Cod extension); Assembly with source code generates source codes and assembly code files (. ASM extension); Assembly, Machine code,and source generates machine code, source code, and assembly code files (. Cod extension). Listing file name is the path to the generated information file, typically in the debug or release directory, and the generated file name automatically takes the file name of the source file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.