Document Source:
Pragma Directives, Preprocessor Reference, Visual C Programmer Guide.
Each C and C implementation supports the only function of its host or operating system. For example, some programs need to accurately control the storage space where the data is located, or the way to control specific functions accept parameters. #pragma indicates that each compiler provides specific functions of different machines and operating systems when retaining the overall compatibility of C and C languages. Compile instructions are defined as machines or operating systems specific and usually each compiler is different.
grammar:
#pragma token_string
"Token_string" is a series of characters to give the required specific compiler commands and parameters. The number symbol "#" must be the first non-empty character in the line that contains the compilation instruction; and the blank character can be separated from the digital symbol "#" and keyword "pragma". Behind #pragma, write any translation program as a text of the pre-processing symbol analysis. #pragma's parameters are similar to macro extension.
If the compiler finds that it does not recognize a compilation indication, it will give a warning, but the compile will continue.
In order to provide new preprocessing, or provide information on the implementation defined by the compiler, the compilation indication can be used in one conditional statement. C and C compilers can identify the following compiler 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 once warning
* Is only used for C compilers.
1 Alloc_Text
#pragma alloc_text ("TextSection", Function1, ...)
Name special defined function resident code segment. This compilation indication must appear between the function specifier and the function definition.
Alloc_text compiles not processes the C member function or overload function. It can only be applied in a C-connection mode, that is, the function is description by the extern "C" connection indicator. If you try to apply this compilation indication to a function with a C connection, a compiler error will appear.
Since the function addresses using __based are not supported, you need to use the alloc_text compilation indication to specify the segment location. The name specified by TextSection should be enclosed by a double quotation.
Alloc_text compile instructions must appear after any function description that needs to be specified, and before the definition of these functions.
The function referenced in the Alloc_Text Compilation Instruction must be in the same module with the compilation indication. If this is not done so that the error may not be captured when a unseserive function is compiled into a different code segment. Even if the program generally runs normally, the function will not assign the paragraph to which it should be.
Other restrictions on alloc_text are as follows:
It cannot be used inside a function.
It must be used for function descriptions, before the function definitions.
2 auto_inline
#pragma auto_inline ([{on | OFF}])
This range can be considered as a function as an automated embedded extended candidate when specifying OFF. In order to compile instructions using Auto_inline, it is followed by writing it before or after a function definition (not inside it). This compilation indication will work in the first function definition after it appears. Auto_inline Compile Indicates that explicit inline functions do not work.
3 BSS_SEG
#pragma data_seg ([Section-Name "[," Section-Class "]]) Specifies the default segment for uninitialized data. Data_SEG Compilation indicates that there is the same effect in addition to the initialized data rather than uniniterated. In some cases, you can use BSS_SEG to arrange all uninitialized data in a segment to speed your loading time.
#pragma bss_seg ("my_data")
The uninitialized data that will result in the #pragma statement in a segment called MY_DATA.
Compiling the assigned data with BSS_SEG does not contain any information about its location.
The second parameter section-class is used for Visual C for 2.0 version, and it will now be ignored.
4 Check_Stack
#pragma check_stack ([{on | OFF}])
#pragma check_stack { |
If you specify OFF (or "-") indicating the compiler to turn off the stack detection, or specify ON (or " ") to open the stack detection. If the parameters are not given, the stack detection will decide according to the default setting. This compilation indication will take effect in the first function after the indication. Stack detection is neither a macro and a part of the embedded code function.
If you don't give the parameters for check_stack compile instructions, the stack check will be restored to the behavior specified at the command line. See the compiler reference in detail. The mutual effects of the #pragma check_stack and / gs option are described in Table 2.1.
Table 2.1 Compile instructions with Check_Stack
Compile instruction
Compile with / GS options?
behavior
#pragma check_stack () or subsequent #pragma check_stack is a function of stack checking #pragma check_stack Close () NO or subsequent #pragma check_stack stack checking function to open #pragma check_stack (on) or #pragma check_stack ( ) or no subsequent Function Open Stack Check #pragma check_stack (off) or #pragma check_stack (-) is or if you subsequent functions Close Stack Check
5 Code_SEG
#pragma code_seg ([Section-Name "[," Section-Class "]])
Specifies the code segment of the assignment function. Code_SEG Compile Indicates that the function specifies the default segment. You can also specify an optional class name like a paragraph name. #Pragma code_seg without a paragraph string will resume the status of the compilation start.
6 const_seg
#pragma const_seg ([Section-Name "[," Section-Class "]])
Specifies the default segment for constant data. Data_SEG Compilation Indicates that there is the same effect in addition to all data. You can use this compilation indication to save your constant data in a read-only segment.
#pragma const_seg ("my_data")
Constant data caused in the #pragma statement is allocated in a segment called MY_DATA.
Compiling the data indicating allocated with const_seg does not contain any information about its location.
The second parameter section-class is used for Visual C for 2.0 version, and it will now be ignored.
7 Comment
#pragma comment (comment-type [, commentstring])
Arrange the description record to the target file or the executable. Comment-type is one of the five predefined identifiers described below to specify the type of description record. Optional CommentString is a string text value for additional information for some description types. Because CommentString is a string text value, it follows all rules of string text values, such as democol characters, embedded quotes (") and join .7-1 compiler
Place the compiler name and version number in the target file. This description record is ignored by the connection program. If you provide a CommentString parameter for this record type, the compiler will generate a warning.
7-2 Exestr
Place CommentString to the target file. When connecting, this string is placed in the executable file. This string does not be loaded when the executable is loaded, however, it can be found by a program that can search in a file to print a string. One use of this description is an embedded version number or similar information in an executable file.
7-3 LIB
Place a library search record into the target file. This description type must have a CommentString parameter that contains library names (and possible paths) you want to connect. Because the library name is recorded in the target file, the connection program will search if you enter these libraries as you can enter these libraries. You can place multiple library search records in a source file, and each record will appear in the target file in the order in which they appear in the source file.
7-4 Linker
Place the connection program option in the target file. You can use this description type to specify the connection options instead of the options in the Linked page in the Project Setting dialog. For example, you can specify the / include option to force to include a symbol:
#pragma comment (Linker, "/ include: __ mysymbol")
7-5 User
A normal description record is included in the target file. The CommentString parameter contains the text described. This description record will be ignored by the connector.
The following compilation indication results in the connection program to search the EMAPI.LIB library when connecting. The connection program first searches in the current working directory and then searched in the path specified by the lib environment variable.
#pragma comment (Lib, "Emapi")
The following compilation indication causes the compiler to place its name and version number to go in the target file.
The Following Pragma Causes The Compiler To Place The Name and version Number of the Compiler In The Object File:
#pragma comment (Compiler)
Note that for a description of the CommentString parameter, you can use other macros that use the volume of string text to provide macro extensions as string. You can also connect any combination of string text quantities and macros to expand into a string type. For example, the following statement is acceptable:
#pragma comment (user, "compiled on" __date__ "AT" __time__)
8 Component
#pragma component (Browser, {on | OFF} [, reason [, name]])
#pragma Component (MinRebuild, ON | OFF)
Control the collection of browsing information and dependency information from the source file.
8-1 Browse Information (Browser)
You can turn it on or off, you can also specify the special name to ignore the special name.
Use ON or OFF to control the collection of browsing information after compiling indications. E.g:
#pragma Component (Browser, Off)
Terminate the compiler to collect browse information.
Note that in order to open the collection information, you must first allow browsing information from the Project Setting dialog or command line. The REFERENCES option can be available or no name parameters. Use the References option with no name parameters to open or close the collection of reference information (however continues to collect other browsing information). E.g:
#pragma component (browser, off, refresses)
Terminate the compiler collection reference information.
Use the References options with Name and Off parameters to block the names that are referenced from the browsing information window. Use this syntax will ignore the names and types you are not interested in reducing the size of the browsing information file. E.g:
#pragma Component (Browser, Off, References, DWORD)
Ignore DWORD references after this. You can use ON to recover DWORD reference collection:
#pragma Component (Browser, ON, References, DWORD)
This is the only way to resume the reference to the specified name, you must explicitly open any name you close.
In order to prevent the pretreatment program extension (just like extending null to 0), it is enclosed in quotes:
#pragma component (Browser, Off, References, "NULL")
8-2 minimize reconstruction (Minimal Rebuild)
The Minimize Visual C minimizes the compiler to create and save C class dependency information that requires a lot of disk space. In order to save disk space, you can use #pragma Component (MinRebuild, Off) when you don't need to collect dependencies, for example, have not changed the overhead file. Insert #pragma Component (MINREBUILD, ON) after an unmodified class.
See the ENABLE Minimal Rebuild (/ GM) Compiler option.
9 Data_Seg
#pragma data_seg (["Section-Name" [, "Section-Class"]])
Specify the default segment of the data. E.g:
#pragma data_seg ("my_data")
The data saved after the #pragma statement is saved in a segment called MY_DATA.
Compiling Data_SEG Compilation The data that is allocated does not contain any information about its location.
The second parameter section-class is used for Visual C for 2.0 version, and it will now be ignored.
10 function
#pragma function (function1 [, function2, ...])
Specifies that the call to the function in the compile indication must be generated. If you use Intrinsic Compile Instructions (or / OI) to tell the compiler to generate an intrinsic function (the content function is generated as embedded code, not as a function call), you can use the Function to compile indication explicitly forced function calls. When you encounter a Function compilation indication, it will take effect at the first function definition that is included there in it. It continues to act as the tail of the source file or appears to specify an Intrinsic compilation instruction to the same internal system. Function compile indication can only be used outside the function - at the global level.
To list a function table with an inherent form, see #pragma intrinsic.
11 HDRSTOP
#pragma hdrstop [("filename")]]
Control the work mode of the precompiled head file. FileName is the name of the pre-compiled head file to use or create (depending on whether to specify / yu or / yc). If FileName does not include a specified path, it is assumed that the precompiled head file and the source file are in the same directory. When you specify an automatic pre-translated header file option / YX, all specified file names will be ignored. If there is a / yx or / yc option, and the C or C file contains an HDRSTOP compilation indication, the compiler saves the compilation status before compiling. The compilation status after the compilation indication is not saved.
HDRSTOP compilation options cannot appear in a header file. It can only appear in the file level of the source file, and it cannot appear in any data or instructions or definitions of the function.
Note that the HDRSTOP compilation indication will be ignored unless the / yx option or / yU or / yus option is specified.
Naming with a file name to save the pre-compiled status file. The space between HDRSTOP and FILENAME is optional. The file name in the HDRSTOP compilation indication is a string so that it obeys the C or C string rules. In particular, you must have a quotation that is displayed in the following example.
#pragma hdrstop ("c: /projects/include/myinc.pch")
The file name of the pre-translated head file is determined according to the following rules, according to the priority:
/ FP compiler option parameters;
FileName parameters from #pragma hdrstop;
The basic file name of the original file name plus the .PCH extension.
12 Include_Alias
#pragma include_alias ("long_filename", "short_filename")
#pragma include_alias (
Specifies the short_filename as a long_filename alias. Some file systems allow for a long file name that exceeds 8.3fat file system restrictions. The compiler cannot simply cut the long file name as 8.3 name, because the first 8 characters of the long file name may not be unique. Whenever the compiler encounters a long_filename string, it replaces short_filename and uses a short_filename to search the header file. This compilation indication must appear before the corresponding #include indicator. E.g:
// First Eight Characters of these Two files 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"
This alias is exactly matched at the time of search, including spelling and double quotes, angle brackets. Include_alias compiles instructions to perform simple string matches on the file name without performing other file name verification. For example, give the following instructions:
#pragma include_alias ("mymath.h", "math.h")
#include "./mymath.h"
#include "sys / mymath.h" does not perform alias, because the header file name string does not have exactly match. In addition, the header name as the parameter is not replaced as the header name of the parameter in the / yu, / yc, and / yx compiler option, or the HDRSTOP compilation indication. For example, if your source file contains the following instructions:
#include
The corresponding compiler option must be:
/Ycapplesystemheaderstop.h
You can compile instructions with include_alias to map any header file to another file. 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 enclosed in double quotes and sharp brackets. For example, when the #pragma include_alias instruction is given, the compiler is not executed in the following #include instruction below.
#include
#include "stdio.h"
Also, the following instructions will produce an error:
#pragma include_alias (
Note that the file name reported in the error message, or the value of the predefined macro __file__ is the file name after the replacement. For example, after the following instructions:
#pragma include_Alias ("VeryfileName.h", "MyFile.h")
#include "VerylongFileName.h"
File VeryLongFileName.h produces the following error message:
MyFile.h (15): Error C2059: SYNTAX Error
It is also important to not support delivery. Give the following instructions:
#pragma include_alias ("one.h", "two.h")
#pragma include_alias ("two.h", "three.h")
#include "one.h"
The compiler will search for TWO.H instead of three.h.
13 init_seg
C unique
#pragma init_seg ({Compiler | LIB | User | "Section-Name" [, "func-name"]})
Specifies the keyword or code segment that affects the startup code. Because the initialization of global static objects can include execution code, you must specify a keyword to define when constructed objects. It is especially important to use the init_seg compilation indication when using the Dynamic Library (DLL) or library that needs to be initialized.
The options for the init_seg compile indication are:
13-1 compiler
Run the time library by Microsoft C. The object in this group will be constructed.
13-2 LIB
Used for initialization of third-party library developers. Objects in this group will be constructed before the object marked as constructed Compiler.
13-3 User
Used for any other user. The object in this group will last constructed.
13-4 Section-Name
Allows explicitly designation of the initialization segment. The objects in the section-name specified in the user will not be implicitly constructed, and their addresses will be placed in segments named after Section-Name. 13-5 Func-Name
Specifies the function called as an ATEXIT function when the program exits. This function must have the same form as the ATEXIT function:
INT funcname (void);
If you need to delay initialization, you can choose to specify the explicit segment name. You must then call the constructor of each static object.
14 inline_depth
#pragma inline_depth ([0 ... 255])
Control the occurrence of the embedded function extension by controlling a series of functions (from 0 to 255 times) that can be extended, this compilation indication controls the embedded function that can be automatically embedded with INLINE, __INLINE or in / OB2 option.
Inline_Depth Compilation Indicator Controls a series of function calls that can be extended. For example, if the embedding depth is 4, and if a call B and then call C, all 3 calls will be embedded. However, if the most recent embedded depth of setting is 2, only A and B are expanded, and C is still called as a function.
In order to use this compilation instruction, you must set the compiler option / ob be 1 or 2. Use this compilation instruction to set the specified depth setting to take effect at the first function behind the indication. If you do not specify a value in parentheses, inline_Depth sets the embedded depth to the default value 8.
In expanding, the embedded depth can be reduced without being increased. If the embedded depth is 6, the pre-processing in the extended process encounters an inline_depth compilation indication to 8, the depth remains 6.
The embedded depth 0 will refuse to embed expansion, and depth 255 will set the settings when embedded. If you use a compilation indication without a specified value, use it as the default value.
15 Inline_Recursion
#pragma inline_recursion ([{ON | OFF}])
Control Direct or Inter-Cutomatic Cultivation Calling Embedded Embedded Embedded Equipment. Use this compilation instruction to control the embedded function that can be automatically embedded with the inline, __ inline tag or under the / OB2 option. Use this compilation indication to set the compiler option / ob be 1 or 2. The default inline_recursion status is OFF. This compilation indication does not affect the definition of the function after the first function call after the compilation indication occurs.
Inline_recursion Compilation Indicator Control How to extend the recursive function. If inline_recursion is OFF, and if an embedded function calls itself (direct or indirect), the function will only extends once. If the inline_recursion is ON, the function will extend multiple times until the value of INLINE_DEPTH or the capacity limit.
16 Intrinsic
#pragma intrinsic (Function1 [, Function2, ...])
Specifies that the function call is included in the compilation instruction parameter table. Compile the program like embedding code to generate a function of ambulse, not a function call. The library function with an inherent form is listed below. Once an Intrinsic compilation indication is encountered, it starts from the first function definition that contains the specified internal function. The role continues until the end of the source file or the Function compilation indication containing the same containment function. Intrinsic Compile Indications can only be used outside the function - at the global level.
The following functions have an in-form:
_disable _enable _inp _inpw _lrotl _lrotr _outp _outpw _rotl _rotr _strset abs Fabs labs memcmp memory memset strat strcmp "
Using a function of the inherent function is faster because they do not have an additional price of the function call, but because of the additional code generation, it may be relatively large. Note that _alloca and setjmp functions are always included, this behavior is not affected by Intrinsic compilation.
The following floating point functions have no internal form. However, they have versions that directly transmit parameters through floating point chips rather than pushing the program stack.
ACOS Asin Cosh Fmod Pow Sinh Tanh
When you specify / ib and / og compiler options (or any options containing / OG, / OX, / O1, and / O2), the following floating point functions have a true intrinsic form.
Atan Exp Log10 SQRT Atan2 Log Sin Tan Cos
You can use compiler options / OP or / ZA to override the generation of true floating point options. In this case, the function is generated as a typical library function, and directly transmitting the parameters through a floating-point chip instead of the push program stack.
17 Message
#pragma message (MessageString)
Do not interrupt compilation, send a string text to standard output. The typical application of the Message compile indication is to display information at compile time.
The following code segment is compiled with the Message instruction to display a message during the compilation process:
#if _m_ix86 == 500
#pragma message ("Pentium Processor Build")
#ENDIF
The MessageString parameter can be a macro capable of extending a string text, and you can construct any combination of string text quantities and macros. For example, the following statement displays the date and time of the file name and file last modification of the compiled file.
#pragma message ("compiling" __file__)
#pragma message ("Last Modified On" __timestamp__)
18 once
#pragma overce
Specifies that the file in which the compilation indication is only included (open) once in the creation process. One common usage of this compilation indication is as follows:
//Header.h
#pragma overce
// Your C OR C Code Would Follow:
19 Optimize
Exit only in the professional and enterprise version
#pragma Optimize ("[Optimization-List]", {on | OFF})
Code optimization only Visual C Professional and Enterprise Support. See Visual C Edition for details.
Specifies the optimization execution in the function hierarchy. The Optimize compilation option must appear outside the function and start a role in the first function definition after the compilation indication. The ON and OFF parameters open or turn off the options specified in Optimization-List.
Optimization-List can be 0 or more parameters given in Table 2.2:
Table 2.2 Optimize compiles parameters
parameter
Optimization type
A assumes that there is no alias. g allows global optimization. p Enhance floating point consistency. s or T specify a shorter or faster machine code sequence. w assumes that there is no alias in the function call. Y generates a frame pointer in the program stack.
These and the same letters are used in the / O compiler option. E.g:
#pragma Optimize ("ATP", ON)
The Optimize compilation indication with an empty string ("") is a special form. It either closes all optimized options or restores them to the original (or default) settings.
#pragma optimize ("", OFF)
.
.
.
#pragma Optimize (", ON) 20 PACK
#pragma pack ([n])
Specify the structure and the aqueous alignment of the joint member. Although the structure of the entire translation unit is set with / zp options and the tightening alignment of the federated member, you can use the PACK compilation indication to set a tightening alignment in the data description level. It takes effect from the first structure or joint description of the compilation indication. This compilation indication does not affect the definition.
When you use #pragma pack (n), where N is 1, 2, 4, 8 or 16, and each of the first structures is stored in a smaller member type or an N-byte boundary. If you use a #pragma pack without parameters, the structural member will be tightened to the value specified by / zp. The default / zp tightening size is / zp8.
The compiler also supports the following enhancement syntax:
#pragma pack ([[{Push | POP},] [Identifier,]] [N])
This syntax allows you to merge the components of different tightening compile instructions to the same translation unit.
Each time a PACK compile indication with a Push parameter will save the current tightening alignment to an internal compiler stack. The parameter list of the compilation indication is read from left to right. If you use push, the current tightening value is saved. If you provide a n value, this value will become a new aqueous value. If you specify a marker you selected, this marker will be associated with the new tightening value.
Each time a PACK compile indication indicates a value from the top of the internal compiler stack and the value is aligned as a new tightening. If you use POP, the internal compiler stack is empty, and the alignment value will be obtained from the command line, and a warning is given. If you use POP and specify the value of N, that value will become a new aqueous value. If you use POP and specify a marker, remove all the values stored in the stack until the matching find matching marker, and the tightening value associated with the indicator are also moved from the stack to become new. Tighten the value. If you do not find a matching marker, you will get a tight value from the command line and generate a level 1 warning. The default tightening alignment is 8.
The new enhancements of the Pack compile indication allow you to write header files to ensure that before using the header file and the following tightening value:
/ * File name: incrude1.h
* /
#pragma pack (push, enter_includ1)
/ * Your incrude-file code ... * /
#pragma pack (POP, ENTER_INCLUDE1)
/ * End of incrude1.h * /
In the previous example, the current tightening value and the marker Enter_include1 are associated with the header file and are remembered. The PACK compilation option on the end of the header file is removed to all the tightened values that may be encountered in the head file and remove the aqueous value associated with Enter_include1. Such a header guarantees that before and after the header file is used.
The new feature also allows you to compile the instructions as different code in your code, such as the header file setting different tightening alignment.
#pragma pack (push, before_includ1)
#include "include" include1.h "
#pragma pack (Pop, Before_Include1)
In the previous example, your code is protected to prevent changes in any tightening values in Include.h.
21 Pointers_to_Members
C unique
#pragma pointers_to_members (Pointer-Declaration, [MOST-General-Repesentation])
Specifies whether a pointer to the class member can be described prior to the relevant class definition, and the code for controlling the size of the pointer and the code of the pointer. You can use Pointers_TO_MEMBERS in your source code to replace / VMX compiler options.
The Pointer-Declaration parameter indicates whether you have explained a pointer to the member before or after the correlation function is defined. The Pointer-Declaration parameter is one of the following two symbols: parameters
Description
Full_Generality generates secure, but sometimes you can not optimize code. If there are some pointers that point to the member, you have to use Full_Generality before the pointer to the member is defined. This parameter always uses the pointer specified by the MOST-General-Repesentation. Best_case generates secure, optimized code for all pointers pointing to members. It is necessary to define a class before a pointing member pointer. The default is Best_Case.
The MOST-General-Representaion parameter indicates that the compiler can be securely referenced to any minimum pointer representation of the class member pointer. This parameter can be one of the following:
Parameter Description SINGLE_INHERITANCE The most common representation is single inheritance, pointing to member functions. If used to point to a pointer with multiple or virtual inheritance, it will generate an error. Multi_inheritance is the most common way to say multiple inheritance, pointing to member functions. If it is used to point to a pointer with a virtual inheritance mode, an error will be generated. Virtual_inheritance is the most common way to represent virtual inheritance, pointing to member functions. Will not generate errors. This is the default parameter when #pragma pointers_to_members (full_generality) is used.
22 setLocale
#pragma setlocale ("locale-string")
Define areas (national and languages) used to translate wide character constants and string quantities. Since the algorithm used to convert to wide characters from multibly byte characters is different according to the region or because of the different parts of the executable, this compile indication provides a way to specify the target area when compiling. This ensures that the wide character string will be saved in the correct format. The default locale-string is "c". The "C" area maps each character in the string as WCHAR_T (ie UNSigned int).
23 vtordisp
C unique
#pragma vtordisp ({on | OFF})
Allow hidden attached VTORDISP constructor / destructive functions replacement members. The VTORDISP compilation indication can only be used for code with a virtual base class. If the derived class is overloaded from a virtual base class, the compiler will be introduced into the class according to the virtual base class if the derived constructor or the destructor or destructuring function is pointed to the virtual base class. Additional hidden "vtordisp" domain.
The VTODISP compile option affects the layout behind it. / VD0 and / VD1 options specify the same behavior for the entire module. Specifying OFF to disabate hidden VTORDISP members, specify ON (default) will allow VTORDISP when they need. The VTORDISP is only turned off when the constructor and the destructive function that cannot appear classes pass through the THIS pointer.
#pragma vtordisp (OFF)
Class GetReal: Virtual Public {...};
#pragma vtordisp (ON)
24 Warning
#pragma Warning (Warning-Specifier: Warning-Number-List [, Warning-Specifier: Warning-Number-list ...])
#pragma Warning (push [, n])
#pragma Warning (POP)
Allows you to selectively modify the behavior of the compiler warning information.
WARNING-Specifier can be one of the following values:
WARNING-Specifier
meaning
OnCE only displays the specified information once. DEFAULT The default compiler option is applied to the specified information. 1, 2, 3, 4 references the given warning level to the specified information. Disable does not display the specified information. Error displays the specified information as an error. WARNING-NUMBER_LIST can contain any warning numbers. As shown below, multiple options can be specified in a compilation instruction:
#pragma Warning (Disable: 4507 34; ONCE: 4385; Error: 164)
This is equivalent to:
#pragma Warning (Disable: 4507 34) // Disable Warning Messages
// 4507 and 34.
#pragma Warning (ONCE: 4385) // Issue Warning 4385
// ONLY ONCE.
#pragma Warning (Error: 164) // Report Warning 164
// as an error.
For those warning labels that are generated about code generation, the Warning compile indication is only valid when the function definition is outside. If the specified warning number is greater than 4699 and is ignored when the function is used. The following example illustrates the correct location of the use of Warning compilation indication and then restores the correct location of the code generation warning message:
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 indicates a warning level (1 to 4).
WARNING (PUSH) Compile Indicates the current warning status of all warnings. WARNING (PUSH, N) Save the current state of all warnings and set the global warning level to n.
WARNING (POP) pops up the warning status in the last push in the stack. Any warning state change between PUSH and POP will be canceled. Consider the following example:
#pragma Warning (Push)
#pragma Warning (Disable: 4705)
#pragma Warning (Disable: 4706)
#pragma Warning (Disable: 4707)
// Some Code
#pragma Warning (POP)
At the end of these codes, the POP recovers the state of all warnings (including 4705, 4706, and 4707) to the start of the code.
When you write the header file, you can use Push and POP to ensure that any user-modified warning status will not affect the normal compilation of your header file. Use Push in the place where the header file is started, and POP is used at the end. For example, assume you have a header that cannot be compiled under the level 4 warning, the following code changes the warning level to 3, and then restore it to the original warning level at the end of the header.
#pragma Warning (Push, 3)
// Declarations / Definitions
#pragma Warning (POP)