Chapter 20 Compiles Instructions

xiaoxiao2021-03-06  15

Chapter 20 Compiles Instructions

Each implementation of C and C supports some unique features for its host or operating system. For example, some programs must accurately control the memory area of ​​storage data, or must control specific functions to accept parameters. #pragma instructions give each compiler a method to give the host or operating system proprietary feature in the case where the C and C language is fully compatible. Based on definitions, compilation indication is perfect for machines or operating systems and is different for each compiler.

grammar

#pragma language symbol string

Language symbol strings are a character sequence given a specific compiler instruction and a parameter. The number symbol (#) must be the first non-empty character in the compilation indicator line. Blank characters can separate numbers (#) and word PRAGMA. After #pragma, the translator can be written as any text as the preparation instrument language symbol analysis. #Pragma's parameters are from macro extensions.

If the compiler finds an unrecognized compilation indication, a warning will be issued, but the compile will continue. Compilation instructions can be used in the conditional description to provide new preprocessor features, or provide defined implementation information to the compiler. The C and C compilers recognize the following compilation instructions:

Alloc_text comment init_seg * Optimize

Auto_INline Component Inline_Depth Pack

BSS_SEG DATA_SEG INLINE_RECURSION POINTERS_TO_MEMBERS *

Check_stack function intrinsic setlocale

Code_SEG HDRSTOP MESSAGE VTORDISP *

Const_seg include_alias overce warning *

C compiler support

C compiler proprietary compilation indication

The following is the C compiler proprietary compilation instruction:

* Init_SEGL

Pointers_to_members

* VTORDISP

Init_SEG

C special place

#pragma init-seg ({Complier / lib / user / "section-name" ["func-name"]} This instruction specifies a keyword or code segment that affects the startup code execution order. Since the initialization of global static objects may involve execution code, a keyword that defines when you create an object. It is especially important to use the init_seg compilation indication in the dynamic connection library (DLL) or the initialized library.

The option for the init_seg compile indication is as follows:

Complier

This option remains initialized to the Microsoft C run. The objects in this group were first created. LIB is used in the initialization of third-party library vendors. The objects in this group were created before the Complier flags were created.

User

Used in any user. This group object is finally created.

Section_name

Allow the display specifications of the initialization segment. Objects in a user specifying section-name (segment name) cannot be created implicitly, but their addresses can be placed in segments named in section_name.

FUNC_NAME

Specifies a function called in an exit () place when the program exits. The specified function must have the same feature as the EXIT function: int funcname (Void (__ cdecl *) (void));

If you need to delay the initialization process (eg, in a DLL), you can select the name of the paragraph. The constructor must then be called for each static object.

C special place

Pointers_to_members

C special place

#progma pointers_to_members (pointer description, [most general representation])

This instruction specifies whether a pointer of a class member can be explained before it is defined, and the code used to control the pointer and explain the code required by the pointer. You can compile a Pointers_to_members instruction to the replace / VMX compiler option in your source file.

Pointer Description Parade Specifies that you still explain a member's pointer before or after a correlation function definition. The pointer description parameters are one of the following two symbols:

Participation Description Full_Generality generates security, but often does not optimal code. If any member's pointer is explained before the associated class definition, Full_Generality can be used. This parameter usually uses the most general representation specified by the pointer representation. The equivalent / vmg option BEST_CASE uses the best case for all member pointers (BEST__CASE) to generate the optimal code. Use this parameter is to define such a member pointer description that defines a class. Its default is BEST_CASEBEST_CASE to use the best case for all member pointers (BEST__CASE) to generate the optimal code. Use this parameter is to define such a member pointer description that defines a class. Its default is BEST_CASE

Most generally indicate that the parameters illustrate that in the conversion unit, the compiler can securely reference any minimum pointer representation of the pointer to the class member. This parameter is as follows:

The paramete description SINGLE_INHERITANCE is most generally inherited, the pointer to a member function. For a class definition, a class definition pointing to a member pointer, if its inheritance mode illustrates multiple or virtual, the error Multiple_inheritance will result in the most general representation of multiple inheritance, a pointer to a member function. For a class definition that points to the member pointer, if its inheritance mode is virtual, the error Vitual_inheritance will most generally represent a virtual inheritance, a pointer to a member function. This function will not cause errors. This is a default parameter when using #pragma pointers_to_members (full_generality)

C special place

VTORDISP

C special place

#pragma vtordisp ({on | OFF})

This command allows increasing implicit VTORDISP constructor / destructive function replacement members. The VTORDISP compiles that only the virtual base class is used. If a derived class is overlap the virtual function inherited from the virtual base class, if the derived class constructor or the destructive function calls that the function using the virtual base class pointer, the compiler may increase the implied "VTORDISP "Domain to a virtual base class.

The VTORDISP compilation indication affects its post-class distribution. / VD0 or / VD1 option specifies the same action for the full mode. Specify OFF will suppress implicit VTORDISP members. Specifies the default value to open them in the required position. The VTORDISP instruction is only closed when the class pointer is not possible to call the virtual function at the object pointing to by the THIS pointer.

#pragma vtordisp (OFF)

Class GetReal: Virtual Public {...};

#pragma vtordisp (ON)

C special place

C and C compiler compile instructions

The following is a compilation indication defined for C and C compilers:

Alloc_text component init_seg * Optimize

Auto_inline const_seg inline_Depth Pack

BSS_SEG DATA_SEG INLINE_RECURSI ONPOINTERS_TO_MEMBERS *

Check_stack function intrinsic setlocale

Code_SEG HDRSTOP MESSAGE VTORDISP *

Comment include_Alias ​​Once Warning

* Is only supported by C compiler

Alloc_text # pragma alloc_text ("Text Segment", Function 1, ...)

This instruction is used to name the specified function definition of the code segment that will reside. This compilation indicator must appear between a function specifier and the function definition.

AllOct_Text Compile Indicates that does not process C member functions or overload functions. It is only used in a function described in a C connection, which refers to a function that uses the extern "C" connection specification. If you try to compile this compilation indicating a function for non-C connection, a compilation error will be generated.

Since the function address of the __based is not supported, the specified segment address needs to be compiled using the alloc_text, and the name specified by the text segment should be included in the double quotation.

Alloc_text Compile Indicates that after the specified function description, these functions are defined before. A function reference in an Alloc_Text Compilation Instruction must be defined in the same module of this compilation indication. If not doing so, and an undefined function is then compiled into a different text segment, this error may be found, or you may not find it. Although the program generally operates normally, the function is not assigned to the expected segment. Other restrictions on alloc_text are as follows:

* It cannot be used inside a function.

* It must be used before and before the function has been described.

Auto_INLINE

#pragma auto_inline ([{on | OFF}])

Exclude the function defined in the area specified in the automatic internal extension. In order to use Auto_inline to compile instructions, put it before or immediately after a function definition (not within this function definition). The compilation indication acts when seeing the first function definition after the compilation indication. Compilation indication Auto_INline cannot be applied to explicit inline functions.

BSS_

Seg # pragma data-seg ([Section-Name "[," Section-Class "]])

Specifies the default segment that is not initialized. Data_SEG Compile Indicates that processes have the same effects in initialization or uninitialized data. In some cases, you can use BSS_SEG to accelerate loaded time by placing all uninitialized data in a segment.

#pragma bss_seg ("my_data")

The data that is not initialized after the #pragma statement is assigned to a segment name MY_DATA.

Compiling indicated by BSS_SEG does not retain any information about its location.

The second parameter section_class is used to be compatible with Visual C , and it has now been ignored.

Check_stack

#pragma check_stack ([{on | OFF}])

#pragma check_stack { |

This instruction indicates the compiler to close the stack search when an off (or -) option. Open the search when the ON (or ) option is specified.

If there is no parametry, the stack search is processed by default. A function occurs at the first defined function after seeing this compilation indication. Stack search is neither part of the macro, nor is also part of the inclined function.

If a parameter is not given to the Check_stack compile instruction, the stack check will restore the behavior described in the command line, see "Compiler Reference" for more information. Table 2.1 see Table 2.1 for interaction between #pragma check_stack and / gs option.

Table 2.1 Compile instructions with Check_Stack

The syntax is compiled with / GS option. #Pragma check_stack () or #pragma check_stack is a stack checking the function after turning off the function. #Pragma check_stack () or #pragma check_stack No Open its function stack check #pragma check_stack (on) or # Pragma check_stack is not to open the stack of the function of the function.

Code_seg

#pragma code_seg ([Section-Name "[," Section-Class "]])

This instruction is used to specify a code segment of a assignment function. Code_SEG Compile Indicates the default segment of the function.

You can selectively specify classes and segment names. #Pragmacode_seg with no section-name string can reset it at the beginning of the compilation.

Const_SEG

#pragma const_seg ([Section-Name "[," Section-Class "]])

This instruction is used to specify the default segment for constant data. Data_SEG Compilation Indicates that all data has the same role. You can use this instruction to put all your constant data into a read-only segment.

#pragma const_seg ("my_data")

Causes the instruction to put the cantaneous data of the #pragma statement into a segment name MY_DATA.

Compiling the data using const_seg Indicates allocated data does not keep any information about its location. The second parameter section-class is used to compatibility with the Visual C 2.0 version, and it is now negligible.

Comment

#pragma comment (comment-type, [commentstring])

This instruction puts a comment record into an object file or executable. Comment-type is one of the five descriptions of the predefined identifiers below, which points out the type of annotation record. The optional CommentString is a string text that provides additional information to some comment types. Since CommentString is a string text, it must follow all rules such as essential characters, embedded or quotation marks ("), and mergers for string text.

Complier

This option puts the name and version number of the compiler into the object file. This comment record is ignored by the linker if you give a CommentString parameter for this record, which will generate a warning message.

Exestr

This option puts the CommentString into the object file. When connected, the string is placed in an executable.

This string does not load to the memory with the executable, but it can be found in the file to find a program that can print a string. One purpose of this annotation record type is to embed version number or similar information into an executable file.

Lib

This option records a library search to the object file. The annotation type must have a CommentString parameter. This parameter contains the name of the library that you want to search (possibly containing the path). Since the library name in the object file is before the default library search record, the linker search the library is like you named it in the command line. You can put multiple library search records in the same source file, each record in the same order in which it appears in the source file in the object file.

linker

This option puts a linker option into the object file. You can specify a linker option with this annotation type to replace this option on the Link tab in the Project Setting dialog. For example, you can specify the / include option to force for a symbol:

#pragma comment (Linker, "/ include: __ symbol")

User

This option puts a general annotation into the object file. The CommentString parameter contains the text of the comment. This comment record is ignored by the linker.

The following compilation indication results in the linker to search the EMAPI.lib library when connecting. The connector first searches in the current working directory, and then searches in the path illustrated in the lib environment variable.

#pragma comment (Lib, "Emapi")

The following compile indication causes the compiler to put the name and version number of the compiler into the object file:

#pragma Comment (Complier)

Note: For a comment with CommentString parameters, you can use the macro in any place where you want to use a string text, so that this macro extension is a string text. You can also merge any combination of any string text with the extension of the string text, for example: The following statement is acceptable:

#pragma comment (user, "compiled" __data_ _ "at" _ _Time__)

Component # prgma

Component (Browser, {on | off} [, reason "]] # Pragma Component (MinRebuild, ON | OFF)

This instruction is used to control the collection of browsing information or dependent information within the source file.

Browser

You can turn a collection or close a collection and you can specify a specific name that ignore when you collect information.

Use the ON or OFF option to control the collection of browsing information in front compile instructions. E.g:

#pragma Component (Browser, Off)

This instruction allows the compiler to stop collecting browsing information.

Note: Use this instruction to open the collection of browsing information, and the browsing information must be opened with the Project Settings dialog or command line.

The REFERENCES option can also bring a Name parame. The References option without Name parameters is used to open or close a reference collection (but continue collecting other browsing information at this time). E.g:

#pragma component (browser, off, refresser) This command stops the compiler to stop collecting reference information.

The References option with Name and OFF parameters is used to prevent reference to NAME in the browsing information window. Using this syntax negligible name and type you are not interested, and shorten the size of the browsing information. E.g:

#pragma Component (Browser, Off, References, DWORD)

Ignore the reference for DWORD before Ignore. But you can use the ON option to reopen the collection of DWORD references.

#pragma Component (Browser, ON, References, DWORD)

This is the unique way to restore the Name reference collection; in this way you can explicitly open any Name you have closed.

In order to prevent the pre-processor from unfolding the NAME (such as 0), add the quotation mark:

#pragma component (Browser, Off, References, "NULL")

Minimal Rebuild

Visual C Minimal Rebuild features requires a compiler to create and store C classes that depend on information, which will take up disk space. In order to save disk space, you can use only #pragma component (minirebuild, off) when you don't need to collect dependencies, for example, in the unchanged header file. Insert #pragma Component (MINREBUILD, ON) can be reopened after the unchanged class.

See the Enable Minimal Rebuild (/ GM) compiler option for more information.

Data_Seg

#pragma data_seg (["Section-Name" [, "Section-Class"]])

This instruction specifies the default segment of the data. E.g:

#pragma data_seg ("my_data")

The data allocated after the #pragma statement is placed in a segment with name my_data.

Compiling Data_SEG Compile Indicates that the assigned data does not retain any information about its location.

The second parameter section-class is used to be compatible with Visual C 2.0, and it is now negligible.

FUNCTION

#pragma function (function1 [, function2, ...])

This instruction specifies the function that specifies the call in the generated compiler to compile the parameter table. If you use Intrinsic Compilation Instructions (or / OI) to tell the compiler to generate an intrinsic function (generated as an inline code, inside the inner function called by the function), you can explicitly call a function with the Function compilation indication. When a function compile indication, it acts at the first function definition of the first specified intrinsic function, which continues until the end of the source file or the compilation indication of this same inner function. At the global layer, the Function compile indication can only be used outside of one function. For a function table with an internal form, see #pragma Intrinsic.

HDRSTOP

#pragma hdrstop [("filename")]]

This instruction is used to control the mode of operation of the precompiled head file. FileName is the name or created by the pre-translated header file (decided according to the specified option / yu or / yc). If FileName does not include a path description, the pre-translated header file will be assumed in the same directory as the source file. All FileName is ignored when specifying the / yx automatic precompiled head file option.

When using / yx or / yc compile, a C or C file contains an HDRSTOP compilation indication that will store the compilation status into the location of the compilation indication. The compilation status of any code will not store the compilation instruction.

HDRSTOP compilation indication cannot appear in a header file. It must appear in the source file. This means that it cannot appear in any data, function description, or function definition.

Note: HDRSTOP compilation indication will be ignored unless / yx option or no file name is specified.

This instruction uses the FileName named the precompiled head file stored in the compile state. One gap between HDRSTOP and FILENAME is optional. The file name described in the HDRSTOP compilation instruction is a string and must be subject to the constraint from the C or C string. In particular, it is necessary to put it in parentheses as shown in the following example:

#pragma hdrstop ("c: /projects/include/myinc.pch")

The name of the pre-translated head file is determined by the following rules, the order is as follows:

1. The parameter of the FP compiler option.

2. #pragma hdrstop filename parameters.

3. The base name of the source file with .pch is the extension.

INCLUDE_ALIAS

#pragma include_alias ("long_filename", "short_filename")

#pragma include_alias (,)

This instruction specifies the alias of the long_filename as a long_filename. Some file systems allow for a longer file name than the 8.3 FAT file system. The compiler is not able to simply put a longer header name is from 8.3 format, as this longer header name may not be unique. As long as the compiler encounters a long_filename string, use short_filename and replaced the SHORT_FILENAME header file. This compilation indication must appear before the corresponding #include directive,

E.g:/

/ Eight characters of the beginning of these two files are not unique

#pragma include_alias ("AppleSystemHeaderQuickDraw.h", "QuickDra.h")

#pragma include_alias ("AppleSystemHeaderfruit.h", "fruit.h")

#pragma include_alias ("graphicsmenu.h", "gramenu.h")

#include "applesystemheaderquickdraw.h"

#include "applesystemheaderfruit.h"

#include "graphicsmenu.h"

Whether it is spelling, or double quotation or sharp brackets, the alias that is searched must meet specifications. Include_alias compiles to handle simple string matches in this file name, and in other file names are invalid. For example, give the following instructions:

#pragma include_alias ("mymath.h", "math.h")

#include "./mymath.h"

#include "sys / mymath.h"

No alias is executed using (replace), because the header file string does not match. The header name used for / yu, / yc, and / yx compiler option, or the header name of the HDRSTOP compile indication cannot be replaced. For example, if your source file contains the following instructions:

#include

The corresponding compiler option should be:

/Ycapplesystemheaderstop.h

You can compile instructions with include_alias to map any header file name to another. E.g:

#pragma include_alias ("API.H", "C: /Version1.0/API.H")

#pragma include_alias (,)

#include "api.h"

#include

Do not confuse the file names in the double quotes and the file names within the brackets, for example, for the two #pragma include_alias instructions given above, the compiler does not perform any replacement in the #include instruction below:

#include

INCLUDE "stdio.h"

In addition, the following instructions will result in errors:

#pragma include_alias (, "Header.h") // Error

Note that the file name given in the error message, or the value of the predefined __file__ macro is the name of the file after execution, for example, after the following instructions: #pragma include_alias ("VeryLongFileName.h", "MyFile .h ")

#include "VerylongFileName.h"

An error in VerylongFileName.h will result in an error message:

MyFile.h (15): Error C2059: SYNTAX Error

At the same time, pay attention to the transmissionability is not supported. In the following instructions:

#pragma include_alias ("one.h", "two.h")

#pragma include_alias ("two.h", "three.h")

#include "one.h" compiler search is file Two.h instead of three.h.

INLINE_DEPTH

#pragma inline_depth ([0 ... 255])

This instruction controls the number of times the inline expansion can occur by controlling the number of times (from 0 to 255 times) that can be extended by controlling a series of function calls. This compilation indication control is a built-in function that is labeled as inline and __inline, or a function that has been automatically wrapped under the / OB2 option.

Inline_Depth Compile Indication Controls the number of times a sequence function call can be expanded, for example, if the wedge depth is 4, and if a call B, B call C, three calls are extended. However, if the nearest inline is extended to 2, only A and B are expanded, and c remains as a function call.

To use this compilation instruction, you must set the / oblay option to 1 or 2. The depth setting of this compilation indication takes effect at the first function after the compilation instruction command. If you do not specify a value in parentheses, INLINE_DEPTH will set the widget depth as the default value 8.

The wedding depth is only reduced in the expansion. When the wedge depth is 6, and in the expansion, the preprocessor encounters an inline_Depth compilation indication of a wedding depth value of 8, which remains 6.

Board depth 0 prohibits cable expansion; the widow depth 255 is unlimited to the connection expansion. If a compilation indication that does not specify its value is used, its default value will be used.

INLINE_RECURSION

#pragma inline_recursion ([{ON | OFF}])

This instruction controls the connection extension of the direct or mutual recursive function. This instruction is used to control functions labeled inline and __inline, or the compiler is automatically extended under the OB2 option. The usage of this compilation indication requires an / OB compiler option set to 1 or 2. The default status of Inline_Recursion is OFF. This compilation indication only works at the first function after it appears, and does not affect the definition of the function.

Inline_recursion Compilation Indicates how the recursive function is expanded. If INLINE_RECURSION is closed, and if a connection function calls itself (direct or indirect), the function is only extended once. If inline_recursion is open, the function will be extended multiple times until it reaches the value of inline_Depth, or the limit of its capacity value.

Intrinsic # prgma

Intrinsic (Function1 [, Function2, ...])

This instruction specifies that the call to the function described in the compilation indicator parameter table is intrinsic. The compiler generates the intrinsic function of the icon code, not like the function call. Library functions with intrinsic format are as follows. When encountered an Intrinsic compilation indication, it acts at a first function definition containing the specified intrinsic function, its function continues to the end of the source file, or until a FUNCTION compilation indication that explains the same inner function .

Intrinsic Compile Indications can only be used outside of a function (full level).

The following functions have intrinsic format:

_disable _outp Fabs Strcmp

_Nable_outpw Labs Strcpy

_INP _ROTL MEMCMP STRLEN

_inpw _ROTR MEMCPY

_LROTL _STRSET MEMSET

_LROTR ABS STRCAT

Programs that use internal functions are faster because they do not have additional overhead of function calls, but they will be more than the resulting extra code.

Note: _alloca and setjmp functions are always built-in generated, which is not affected by the Intrinsic compilation indication. The floating point functions listed below have no real inner format. But they have this version: send the parameters directly into the floating-point chip, rather than pressing them into the program:

ACOS COSH POW TANH

Asin fmod sinh

When you specify / oi and / og compiler options (or any options including / OG, / OX, / O1, and / O2 options), the following floating-point functions have real intrinsic format:

Atan Exp Log10 SQRT

Atan2 log sin tan

COS

You can use the / OP or / ZA compiler option to overlap the generated inner floating point option. In this case, the function is generated as a library routine, which is directly sent to a floating-point chip instead of pressing them into the program.

Message

#pragma message (MessageString)

This instruction does not terminate compilation, and send a string text directly to the standard output. The typical usage of the Message Compile Indication is to display the information gap at compile. The following code segment uses the Message to compile indication to display a message at compile:

#if _m_ix86 == 500

#pragma

Message ("Pentium Processor Build") # EndifMessageString parameter can be a macro that can be expanded into a string text, and you can combine these macros with a string text in any combination. For example, the following statement shows the date and time of the compiled file name and the final change of the file:

#pragma message ("compiling" __file__)

#pragma message ("Last Modified On" __timestamp_ _)

ONCE

#pragma overce

This instruction specifies that the file that resides in the compilation indication will only be (open) once in one establishment. A common usage of this compilation indication is as follows:

//Header.h

#pragma overce

/ / Next is your C or C code

Optimize

#pragma Optimize ("[Optimization-List]", {on | OFF})

Features of professional and enterprise versions only: Code optimization is only supported by Visual C Professional and Enterprise Edition. For more information, see Microsoft Visual C online editing.

This instruction specifies the optimization executed in the function base. The Optimize compile indication must appear outside of a function and acts at the first function that the compilation indication is displayed. ON and OFF parameters can open or close the options specified in Optimization-List.

Optimization-List can be 0 or parameters in Table 2.2.

Table 2.2 "Optimization" Compile Instructions Parameters

Parameter Optimization Type A Assumption No alias G Allows global optimization P to increase floating point compatibility S or t Specify the short or fast sequence of machine code in the machine code, assume the alias Y generated the frame pointer in the program stack in the plug

These are the same letters as the / O compiler option, such as:

#pragma Optimize ("ATP", ON)

The use of an empty string ("") using the Optimize compile indication is a special form of the instruction, which offs off all optimized or restored their original (default) settings.

#pragma optimize ("", OFF)

...

#pragma optimize ("", "

Pack

#pragma pack ([n])

This instruction specifies the compact alignment of the structure and the federated member. And a complete conversion unit structure and combination

The compact alignment is set by / zp option. Compact alignment PACE compile indication is set in the data sheet. This compilation indication takes effect at the first structure or joint description thereof. This compilation indication is invalid for the definition. When you use #pragma pack (n), the N is 1, 2, 4, 8 or 16 here. Each struct member after the first structural member is stored in a smaller member type or N-byte limits. If you use a non-reflected #pragma Pack, the structural member is compact to the value specified by / zp. This default / zp compact value is / zp8.

The compiler also supports the following enhanced grammar:

#pragma pack ([[{Push | POP},] [Identifier,]] [N]) If the different components use the Pack-Compiling indication to specify different compact alignment, this syntax allows you to combine program components as a separate conversion. unit.

Each appearance of the PUSH parameter is stored in an internal compiler stack each appearing with a Push parade. The parameter table of the compilation indication is read from left to right. If you use push, the current compact value is stored; if you give a N value, this value will become a new compact value. If you specify an identifier, you select a name, then the identifier will link with this new compact value.

Each appearance of a PACK compilation indication with a POP parameter retrieves the value of the internal compiler stack and makes the value a new compact alignment value. If you use the POP parade and the internal compiler stack is empty, the compact value is a value given by the command line, and will generate a warning message. This value will become a new compact value if you use POP and specify a value.

If you use a POP and specify an identifier, all the values ​​stored in the stack will be deleted from the stack until a matching identifier is found, the compact value related to the identifier is also removed from the stack, and this is only The compact value exists before the identifier enters the stack becomes a new compact value. If the matching identifier is not found, the compact value set by the command line will be used, and one level warning will be generated. The default is more compact alignment 8.

The new enhancement of the Pack compile indication allows you to write the header file to ensure that the compact value before and after the header is encountered.

/ * File name: incrude1.h * /

#pragma pack (push, enter_includ1)

/ * Your included file code ... * /

#pragma pack (POP, ENTER_INCLUDE1)

/ * Include1.h end * /

In the above example, the current compact value is associated with the identifier enter_include1 and is pressed into the header file. Pack compile instruction at the end of the header file Delete all the interventions that may appear in the header file and delete the compact value associated with Enter_inClude1. Therefore, make sure the front and rear compact values ​​of the header file are the same.

This new feature also allows you to use code, such as header files, which can use the Pack Compile Indicator Settings Unlike the compact alignment of compact values ​​set in your code:

#pragma pack (push, before_includ1)

#include "include" include1.h "

#pragma pack (Pop, Before_Include1)

In the above example, your code is protected for any change in the compact value in Include.h.

SetLocale

#pragma setlocale ("locale_string")

This instruction defines its location (national and languages) when translated wide characteristic and string text. Since the algorithm for converting multi-byte characters is a wide bit character may differ due to place or compilation, the execution file can be run in different places. This compilation indication provides a method for giving a target location at compile. This ensures that the wide string stores in the correct format. The default Locale_ _String is "C". "C" places map characters in each string to a Wchar_t (unsigned short) value.

Warning

#pragma Warning (Warning-Specifier: Warning-Number-List

WARNING-SPECIFIER: WARNING-NUMBER-LIST ...]])

#pragma Warning (Push [, N]) # Pragma Warning (POP)

This instruction allows you to selectively change the warning message of the compiler.

Warning-specifier can be one of the following values:

Warning indicator meaning

OnCE only shows that the specified message DEFAULT will be applied to the specified message by default compiler behavior.

1, 2, 3, 4 applied a given warning level to the specified warning message

Disable does not issue a designated warning message

Error as a warning specified as an error report

WARNING-NUMBER-LIST (Warning Number) can contain any warning numbers. Multiple options can be specified in the same compilation instruction instructions:

#pragma Warning (Disable: 4507 34; Once: 4385; Error: 164) Its function wants to be true:

#pragma Warning (Disable: 4507 34) // No warning message 4507 and 34. # pragma Warning (ONCE: 4385) // Only warning 4385

#pragma Warning (Error: 164) / / As an error report warning 164

This Warning compile indication is only valid when the function definition is related to the code generation. If the warning number is greater than 4699 or in the function body, it is ignored that the compilation indication is ignored. The following example points out the correct position of the WARNING compilation indication, and then restores a code generation of warning messages.

Int a;

#pragma Warning (Disable: 4705)

Void func ()

{

a;

}

#pragma Warning (Default: 4705)

Warning compile instructions also support the following syntax:

#pragma Warning (push [, n])

#pragma Warning (POP)

Here n represents warning levels (1 to 4).

Compiling Warning (PUSH) Stores all warning status. Compiling Warning (PUSH, N) Stores all current warning status of all warnings and sets the global warning level to n.

Compiling indication Warning (POP) will pop up the last push-out of the stack, and any changes in the warning status between PUSH and POP will be canceled. Consider this example:

#pragma Warning (Push)

#pragma Warning (Disable: 4705)

#pragma Warning (Disable: 4706)

#pragma Warning (Disable: 4707)

// Some code

#pragma Warning (POP)

In this code, the POP recovers all warning status (including 4705, 4706, and 4707) for its warning status at the beginning of the code.

When you write the header file, you can use PUSH and POP to ensure changes in the warning status caused by the user, and does not affect the correct compilation of the head. PUSH is usually used at the beginning of the head, and POP is used at the end. For example, there is a head that is not completely compiled at the warning level 4. The following code change the warning level to 3, then restores the original warning level at the end of the head:

#pragma Warning (Push, 3)

// Description / Definition

#pragma Warning (POP)

转载请注明原文地址:https://www.9cbs.com/read-46708.html

New Post(0)