# Pragma usage Overview

Source: Internet
Author: User
Tags microsoft c
Each implementation of C and C ++ supports some unique features for its host or operating system.
For example, some programs must precisely control the storage area where data is stored, or control the way a specific function accepts parameters.
# The Pragma command provides a method for each compiler to provide the unique features of the host or operating system while maintaining full compatibility with C and C ++ languages.
According to the definition, the compilation instructions are proprietary to machines or operating systems and are different for each compiler.

Syntax
# Pragma string

A linguistic symbol string is a character sequence that provides specific compiler instructions and parameters. The numeric symbol (#) must be the first non-blank character in the compilation indicator line. White space characters can be separated by numerical symbols (#) and the word Pragma. After # pragma, you can write any text translated by a translator as a pre-processor language symbol analysis. # Pragma parameters are macro extensions.

If the compiler finds an unrecognized Compilation instruction, a warning is issued, but the compilation continues. Compilation instructions can be used in condition descriptions to provide new pre-processor functions or provide defined implementation information to the compiler.

C and C ++ compilers can identify 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 once warning *
* Only supported by the C ++ Compiler

C ++ compiler proprietary compilation instructions
The following are the proprietary instructions for compiling C ++ compilers:
* Init_segl
Pointers_to_members
* Vtordisp
Init_seg

C ++
# Pragma init-seg({Complier/lib/user/"section-name" [, "func-name"]}) This command specifies a keyword or code segment that affects the execution sequence of startup code. Because initialization of a Global static object may involve code execution, you must specify a keyword defined when creating the object. It is particularly important to use the init_seg Compilation instruction in the dynamic connection library (DLL) or the library to be initialized.

The init_seg compilation directive has the following options:
Complier
This option is reserved for Microsoft C Runtime Library initialization. Objects in this group are first created. Lib is used for initialization of third-party class library vendors. Objects in this group are created after the complier flag and before other tags.

User
Used by any user. This group object is last created.
Section_name
Display specifications of the initialization segments are allowed. Objects in a section-Name (segment name) specified by a user cannot be implicitly created, but their addresses can be placed in segments named by section_name.
Func_name
Specifies the function called at exit () when the program exits. The specified function must have the same features as the exit function: int funcname (void (_ cdecl *) (void ));
If you need to delay the initialization process (for example, in a DLL), you can explicitly specify the name of the segment. Then the constructor must be called for each static object.
C ++ ends

Pointers_to_members
C ++
# Progma pointers_to_members (pointer description, [most common expression])
This command specifies whether the pointer of a class member can be described before its definition, and is used to control the pointer size and explain the Code required by the pointer. You can put a pointers_to_members Compilation instruction into your source file to replace/vmx compiler options.

The pointer indicates whether the parameter specifies the pointer of a member before the definition of an associated function. Pointer description parameters are one of the following two symbols:
Parameter description
Full_generality generates secure, but often not optimal code. If the pointer of any member is described before the associated class definition, full_generality can be used. This parameter usually uses the pointer representation that most commonly represents the specified parameter. Equivalent to/vmg options

Best_case indicates that the best _ case code is generated for all member pointers. To use this parameter, You need to define this parameter before defining the member pointer description of a class. The default value is best_case.

Best_case indicates that the best _ case code is generated for all member pointers. To use this parameter, You need to define this parameter before defining the member pointer description of a class. The default value is best_case.

The most common parameter represents the minimum pointer representation in the conversion unit that the compiler can safely reference to any pointer pointing to a class member. Take one of the following values for this parameter:
Parameter description
Single_inheritance is generally a single-inherited, that is, a pointer to a member function. For a class definition pointing to a member pointer, if its inheritance mode is described as multiple or virtual, it will cause an error.

Multiple_inheritance generally indicates multiple inheritance, that is, the pointer of a member function. A class definition pointing to a member pointer is described here. If the inheritance mode is virtual, errors will occur.

Vitual_inheritance indicates virtual inheritance, that is, a pointer to a member function. This function will not cause errors. This is the default parameter when # pragma pointers_to_members (full_generality) is used.

C ++ ends

Vtordisp
C ++
# Pragma vtordisp ({on | off })
This command allows you to add implicit vtordisp constructor/destructor to replace members. Vtordisp indicates that only the code of the virtual base class is used. If a derived class overlaps a virtual function inherited from the virtual base class, And a constructor or destructor of the derived class calls the function that uses the virtual base class pointer, then the compiler may add the implicit "vtordisp" domain to a class with a virtual base.

The vtordisp Compilation instruction affects the distribution of subsequent classes. The/vd0 or/vd1 option specifies the same action for the full mode. If off is specified, the implicit vtordisp member is blocked. Specify the default value on and open them at the desired position. The vtordisp command is only disabled when the constructor/destructor of the class points to an object that cannot call a virtual function.

# Pragma vtordisp (off)
Class getreal: virtual public {...};
# Pragma vtordisp (on)
C ++ ends

--------------------------------------------------------------------------------
C and C ++ compiler compilation instructions
The following are the compilation instructions defined for the 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
* Only supported by the C ++ Compiler

Alloc_text
# Pragma alloc_text ("Text Segment", function 1 ,...)
This command is used to name the code segment where the specified function definition will reside. This compilation indicates that the named function must appear between a function Descriptor and the function definition.
Alloct_text indicates that the compilation does not process C ++ member functions or overload functions. It is only used for functions described in the C connection mode. This refers to the function that uses the extern "C" to connect to the Specification Description. If you try to use this Compilation instruction for functions not connected to C ++, a compilation error will be generated.

Because the _ based function address is not supported, the specified segment address must be compiled using alloc_text. The name specified by the text segment should be included in double quotation marks.
Alloc_text compilation instructions must appear after the specified function description, before the definition of these functions. A function reference in the alloc_text Compilation instruction must be defined in the same module of the Compilation instruction. If this is not done, and an undefined function is then compiled into a different text segment, this error may or may not be found. Although the program runs normally, the function is not allocated to the expected segment.

Other restrictions of alloc_text are as follows:
* It cannot be used inside a function.
* It must be used after the specified function and before the defined function.

Auto_inline
# Pragma auto_inline ([{on | off}])
Exclude the functions defined in the off region for candidates for automatic Inline expansion. To compile the instruction using auto_inline, put it before or immediately after a function definition (not within the function definition ). The Compilation instruction takes effect in the first function definition after the Compilation instruction is displayed. Compilation indicates that auto_inline cannot be applied to explicit inline functions.

Bss_seg
# Pragma data-seg (["section-name" [, "section-class"])
Specifies the default segment of uninitialized data. Data_seg compilation indicates that processing initialized or uninitialized data has the same effect. In some cases, you can use bss_seg to accelerate the loading time by placing all uninitialized data in a segment.

# Pragma bss_seg ("my_data ")
As a result, uninitialized data after the # pragma statement is allocated to a segment named my_data.
Compile with bss_seg to indicate that the allocated data will not retain any information about its location.
The second parameter section_class is used for compatibility with earlier versions of Visual C ++ and has been ignored.

Check_stack
# Pragma check_stack ([{on | off}])
# Pragma check_stack {+ | -}
This command instructs the compiler to disable stack search when the off (or-) option is enabled. Open the search when the on (or +) option is specified.
If no parameter exists, stack search is processed by default. The first defined function takes effect after the Compilation instruction is displayed. Stack search is neither a part of a macro nor a part of an inline function.
If no parameter is assigned to the check_stack Compilation instruction, the stack check will be restored to the behavior described in the command line. For more information, see "compiler reference ". # For the interaction between Pragma check_stack and/GS options, see Table 2.1.

Table 2.1 instructions for compiling with check_stack
Whether the syntax is compiled with the/GS option
# Pragma check_stack () or # pragma check_stack is used to disable the stack check of the function afterwards.
# Pragma check_stack () or # pragma check_stack whether to enable the function stack check
# Pragma check_stack (on) or # pragma check_stack + Yes or No stack check of the function after enabling it
# Pragma check_stack (off) or # pragma check_stack-yes or no disable the function stack check

Code_seg
# Pragma code_seg (["section-name" [, "section-class"])
This command is used to specify the code segment of an allocation function. Code_seg indicates that the default segment of the function is specified.
You can selectively specify classes and segments. Use # pragmacode_seg without the section-name string to reset it at the beginning of compilation.

Const_seg
# Pragma const_seg (["section-name" [, "section-class"])
This command is used to specify the default segment for constant data. The data_seg compilation directive has the same effect on all data. You can use this command to put all your constant data into a read-only segment.
# Pragma const_seg ("my_data ")
This command puts the constant data after the # pragma statement into a segment named my_data.
Using const_seg compilation indicates that the allocated data will not retain any information about its location.
The second section-class parameter is used for compatibility with versions earlier than visual C ++ 2.0 and can be ignored now.

Comment
# Pragma comment (comment-type, [commentstring])
This command puts a comment record into an object file or executable file. Comment-type is one of the following five predefined identifiers, which indicate the types of annotation records. Commentstring is a string that provides additional information for some annotation types. Because commentstring is a string, it must follow

This option puts a library search record into an object file. This annotation type must contain a commentstring parameter. This parameter contains the name of the library you want the linker to search for (may contain paths ). Because the library name in the object file is before the default library search record, the linker searches for the library just like you name it in the command line. You can store multiple database search records in the same source file, and each record appears in the same order as it appears in the source file.

Linker
This option puts a linker option into the object file. You can use this annotation type to specify a linker option, which is used to replace the option on the Link tab in the project Setting dialog box. For example, you can specify the/include option to forcibly include a symbol:

# Pragma comment (linker, "/include :__ symbol ")
User
This option puts a general comment into the object file. The commentstring parameter contains the text of the comment. This annotation record is ignored by the linker.
The following compilation instructions cause the linker to search for the emapi. Lib library during connection. This connector is first searched in the current working directory and then in the path of LIB environment variable description.
# Pragma comment (Lib, "emapi ")
The following compilation instructions cause the compiler to put the name and version number of the compiler into the object file:
# Pragma comment (complier)
Note: For a comment with the commentstring parameter, you can use a macro wherever you want to use a string text, so that the macro can be extended into a string text. You can also combine any combination of a string text with a macro extended as a string text. For example, the following statement is acceptable:

# Pragma comment (user, "compiled on" _ DATA _ "at" _ time __)

Component
# Pragma
Component (browser, {on | off} [, references [, name]) # pragma component (minrebuild, on | off)

This command is used to control the browsing information or dependency information set in the source file.
Browser
You can open or close a collection and specify a specific name to ignore when collecting information.
Use the ON or OFF option to control the set of browsing information indicated by the previous compilation. For example:
# Pragma component (browser, off)
This command stops the compiler from collecting browsing information.
Note: Use this command to open a set of browsing information. You must use the Project Settings dialog box or command line to open the browsing information.
The references option can contain or does not contain the name parameter. The references option without the name parameter is used to open or close the referenced set (but other browsing information is collected at this time ). For example:
# Pragma component (browser, off, references)
This command causes the compiler to stop collecting reference information.
The references option with the name and off parameters to prevent reference to the name in the browser information window. Using this syntax can ignore names and types that you are not interested in, and shorten the size of browsing information. For example:

# Pragma component (browser, off, references, DWORD)
Ignore the previous DWORD references. However, you can use the on option to re-open the collection referenced by DWORD.
# Pragma component (browser, on, references, DWORD)
This is the only way to restore a name reference set. In this way, you can explicitly open any name that you have disabled.
To prevent the Preprocessor from expanding the name (for example, extending null to 0), enclose it with quotation marks:
# Pragma component (browser, off, references, "null ")
Minimal rebuild
The minimal rebuild (minimum reconstruction) feature of Visual C ++ requires the compiler to create and store the C ++ class of dependency information, which will occupy disk space. To save disk space, you can only use # pragma component (minirebuild, off) when you do not need to collect dependency information, for example, in the unchanged header file. Insert # pragma component (minrebuild, on) after the unchanged class to re-open the dependency information.

For more information, see enable minimal rebuild (/GM) compiler options.

Data_seg
# Pragma data_seg (["section-name" [, "section-class"])
This command specifies the default data segment. For example:
# Pragma data_seg ("my_data ")
Put the data allocated after the # pragma statement in the segment named my_data.
Using data_seg compilation indicates that the allocated data does not retain any information about its location.
The second parameter section-class is used for compatibility with versions earlier than visual C ++ 2.0 and can be ignored now.

Function
# Pragma function (function1 [, function2,...])
This command specifies the called function in the generated compiler compilation indicator parameter table. If you use intrinsic compilation instructions (or/OI) to tell the compiler to generate an internal function (which is generated as an internal code instead of an internal function called by the function ), you can use the function compilation instructions to explicitly force a function to be called. When a function compilation indicator appears, it acts at the first function definition that contains a specified internal function, this function continues until the end of the source file or until a Compilation instruction indicating the same internal function appears. At the global layer, the function Compilation instruction can only be used outside a function. For function tables with internal form, see # pragma intrinsic.

Hdrstop
# Pragma hdrstop [("FILENAME")]
This command is used to control how pre-compiled header files work. Filename is the name used or created by the precompiled header file (determined by the specified option/YU or/YC ). If filename does not include the path description, the precompiled header file is assumed to be in the same directory as the source file. When you specify the/Yx automatic precompiled header file option, all filename files are ignored.

When/Yx or/YC is used for compilation, a C or C ++ file contains an hdrstop Compilation instruction, which stores the compilation status to the Compilation instruction location. This indicates that no code compilation status is stored after compilation.

Hdrstop compilation indicates that it 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: unless the/Yx option or the/YU or/YC option without a file name is specified, hdrstop compilation instructions will be ignored.
This command uses filename to name the pre-compiled header file stored in the compilation status. A blank space between hdrstop and filename is optional. In the hdrstop Compilation instruction, the file name is a string and must be subject to the constraints of C or C ++ strings. In particular, it must be placed in parentheses

For example:
# Pragma hdrstop ("C: \ projects \ include \ myinc. PCH ")
The names of pre-compiled header files are determined by the following rules. The sequence is as follows:
1./FP compiler option parameters.
2. # filename parameter of Pragma hdrstop.
3. The base name of the source file with the. PCH extension.

Include_alias
# Pragma include_alias ("long_filename", "short_filename ")
# Pragma include_alias (,)
This command specifies short_filename as the alias of long_filename. Some file systems allow longer file names than the 8.3 FAT file system. The compiler cannot simply truncate a longer header file name in 8.3 format, because the first eight characters of this longer header file name may not be unique. As long as the compiler encounters a long_filename string, it replaces it with short_filename and searches for the short_filename header file. This compilation instruction must appear before the corresponding # include command,

Example :/
/The first eight characters of the 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, double quotation marks or angle brackets, the searched alias must meet the specifications. Compile de_alias compilation indicates that simple string matching is processed in the file name, which is invalid in other file names. For example, the following command is provided:

# Pragma include_alias ("mymath. H", "math. H ")
# Include "./mymath. H"
# Include "sys/mymath. H"
No alias is used (replaced) because the header file string does not match. The header file name used as the/YU,/YC, And/Yx compiler option parameter, or the header file name indicated by hdrstop compilation cannot be replaced. For example, if your source file contains the following commands:

# Include
The corresponding compiler options should be:
/Ycapplesystemheaderstop. h
You can use the include_alias Compilation instruction to map any header file name to another one. For example:
# Pragma include_alias ("API. H", "C: \ version1.0 \ API. H ")
# Pragma include_alias (,)
# Include "API. H"
# Include
Do not confuse the file names in double quotes with those in angle brackets. For example, for the two # pragma include_alias commands given above, the compiler will not execute any replacement in the # include command below:

# Include
Include "stdio. H"
In addition, the following command will cause an error:
# Pragma include_alias (, "header. H") // Error
Note that the file name provided in the error message or the pre-defined _ file _ macro value replaces the name of the file after execution. For example, after the following command:
# Pragma include_alias ("verylongfilename. H", "myfile. H ")
# Include "verylongfilename. H"
An error in verylongfilename. H will cause the following error message:
Myfile. H (15): Error c2059: syntax error
Note that the transmission is not supported. In the following command:
# Pragma include_alias ("One. H", "Two. H ")
# Pragma include_alias ("Two. H", "Three. H ")
# Include "One. H" the compiler searches for files two. h instead of three. h.

Inline_depth
# Pragma inline_depth ([0... 255])
This command controls the number of times a series of function calls can be extended (from 0 to 255) to control the number of times an inline extension can occur. This compilation instruction controls the concatenation of functions marked as inline and _ inline or functions that have been automatically associated under the/ob2 option.

The inline_depth Compilation instruction controls the number of times a series of function calls can be extended. For example, if the depth of the concatenation is 4, and if a calls B, B calls C, all three calls will be extended inline. However, if the most recent inline extension is 2, only A and B are extended, C is retained as a function call.

To use this Compilation instruction, you must set the/ob compiler option to 1 or 2. The deep Settings Using This Compilation instruction take effect in the first function after the instruction is compiled. If you do not specify a value in parentheses, inline_depth sets the concatenation depth to the default value of 8.

The Association depth is not increased during expansion. If the joint depth is 6 and the pre-processor encounters an inline_depth Compilation instruction with the joint depth value of 8 during expansion, the depth remains 6.
The Association depth 0 prohibits the association expansion. The association depth 255 does not limit the expansion of the couplet. If a Compilation instruction with no specified value is used, the default value is used.

Inline_recursion
# Pragma inline_recursion ([{on | off}])
This command controls the linear expansion of direct or recursive function calls. This command is used to control functions marked as inline and _ inline, or functions automatically extended by the compiler under the ob2 option. The usage of this compilation instruction requires a/ob compiler option set to 1 or 2. The default status of inline_recursion is off. This compilation instruction only works in the first function after it appears and does not affect the definition of the function.

Inline_recursion compilation instructs you to control how recursive functions are extended. If inline_recursion is disabled and a federated function calls itself (directly or indirectly), the function is extended only once. If inline_recursion is enabled, the function will be extended. The floating point functions listed below do not have an internal format. However, they have the following version: Send parameters directly to the floating point chip, instead of pushing them into the program Stack:

ACOs cosh POW tanh
Asin fmod Sinh
When you specify/OI and/og compiler options (or any options including/Og,/Ox,/O1, And/O2), the following floating point functions have a real internal format:
Atan exp log10 SQRT
Atan2 log sin Tan
Cos
You can use the/OP or/za compiler option to duplicate the generation of real Internal Floating Point Options. In this case, the function is generated as a database routine, which directly sends parameters to the floating point chip instead of pushing them into the program stack.

Message
# Pragma message (messagestring)
This command directly sends a string to the standard output without terminating compilation. A typical usage of message compilation instructions is to display the message elimination number during compilation. The following code snippet uses message compilation to indicate that a message is displayed during compilation:

# If _ m_ix86 = 500
# Pragma message ("Pentium processor build ")
# Endif
The messagestring parameter can be a macro that can be expanded to a string, and you can combine these macros in any combination.
For example, the following statement shows the compiled file name and the date and time when the file was last modified:
# Pragma message ("Compiling" _ file __)
# Pragma message ("Last modified on" _ timestamp __)

Once
# Pragma once
This command specifies that the file where the Compilation instruction resides will be included (opened) by the compiler only once during creation. A common usage of this compilation instruction is as follows:
// Header. h
# Pragma once
// Your C or C ++ code

Optimize
# Pragma optimize ("[Optimization-list]", {on | off })
Features for professional and enterprise editions only: code optimization is only supported by Visual C ++ Professional Edition and Enterprise Edition. For more information, see Microsoft Visual C ++ online editing.
This command specifies the optimization performed in the function base. The optimize Compilation instruction must appear outside of a function and act at the first function defined after the Compilation instruction appears. The ON and OFF parameters can enable or disable the options specified in the Optimization-list.

Optimization-list can be 0 or a parameter is provided in Table 2.2.
Table 2.2 "optimized" Compilation indicator parameters
Parameter Optimization Type
A Assumes that no alias exists.
G allows Global Optimization
P improves floating point compatibility
S or t specifies the short or fast sequence of machine code
W. Assume that there is no alias for cross function calls.
Y generate framework pointer in the program Stack
These are the same letters using the/o compiler option, for example:
# Pragma optimize ("ATP", on)
Using an empty string ("") with optimize compilation instructions is a special form of this command, which can disable all optimization or restore their original (default) settings.
# Pragma optimize ("", off)
...
# Pragma optimize ("", on)

Pack
# Pragma pack ([N])
This command specifies the structure and associated member'sCompact alignment. While the structure of a complete conversion unit and the compact alignment of the Union are set by the/ZP option. Compact alignment is configured at the data description layer with pace compilation instructions. This compilation instruction takes effect in the first structure or joint description after it appears. This compilation instruction is invalid for the definition.
When you use # pragma pack (N), Here N is 1, 2, 4, 8 or 16. Each structure member after the first structure member is stored in a smaller Member type or N-byte limit. If you use the # pragma pack without parameters, the structure members are compact to the value specified in/ZP. The default/ZP compact value is/zp8.

The compiler also supports the following enhanced Syntax:
# Pragma pack ([{push | Pop},] [identifier,] [N])
If different components use pack compilation instructions to specify different compact alignment, this syntax allows you to combine program components into a separate conversion unit.
Each occurrence of pack compilation instructions with push parameters stores the current Compact alignment in an internal compiler stack. The compilation indicator parameter table is read from left to right. If you use push, the current Compact value is stored. If you give a value of N, the value becomes a new compact value. If you specify an identifier, that is, you select a name, the identifier is associated with the new compact value.

Each time a pack compilation indicator with a pop parameter appears, the value at the top of the internal compiler stack is retrieved and the value is a new compact alignment value. If you use the pop parameter and the internal compiler stack is empty, the Compact value is the value given by the command line and a warning message is generated. If you use Pop and specify a value of N, this value will become a new compact value.

If you use Pop and specify an identifier, all values stored in the stack will be deleted from the stack until a matching identifier is found, this compact value related to the identifier is also removed from the stack, and the compact value that exists only before the identifier is imported into the stack becomes a new compact value. If no matching identifier is found, the Compact value set by the command line is used and a level-1 warning is generated. The default compact alignment is 8.

The new enhancements of pack compilation instructions allow you to write header files to ensure that the Compact values before and after this header file are the same.
/* File name: include1.h */
# Pragma pack (push, enter_include1)
/* Your include file code ...*/
# Pragma pack (POP, enter_include1)
/* Terminate de1.h */
In the preceding example, the current Compact value is associated with the identifier enter_include1 and is pushed into the header file. Pack compilation at the end of the header file indicates to delete all compact values that may appear in the header file, and delete compact values related to enter_include1. Therefore, make sure that the Compact values before and after the header file are the same.

This new feature also allows you to use code, such as header files, which can use pack compilation instructions to set compact alignment different from the Compact values set in your code:
# Pragma pack (push, before_include1)
# Include "include1.h"
# Pragma pack (POP, before_include1)
In the above example, your code is protected for any changes to the compact value that appears in include. h.
Setlocale
# Pragma setlocale ("locale_string ")
This command defines the location (country and language) when translating wide character constants and string texts ). Because the algorithm used to convert multi-byte characters into wide characters may vary depending on the location or compilation, the execution file may run differently in different places. This compilation instruction provides a way to give the target location during compilation. This ensures that the wide string is stored in the correct format. The default locale _ string (location string) is "C ". "C" maps the characters in each string to a value of the wchar_t (unsigned short) type.

Warning
# Pragma warning (warning-specifier: Warning-number-list
[, Warning-specifier: Warning-number-list...])
# Pragma warning (push [, N]) # pragma warning (POP)
This command allows you to selectively change the warning messages of the compiler.
Warning-specifier can be one of the following values:
Warning Indicator meaning
Once Only displays the specified message once. Default applies the default compiler action to the specified message.
1, 2, 3, and 4 apply the given warning level to the specified warning message
Disable does not send a specified warning message
Error is the warning specified in the error report.
Warning-number-List (Warning number table) can contain any warning number. In the same Compilation instruction, you can specify multiple options as follows:
# Pragma warning (Disable: 4507 34; once: 4385; error: 164:
# Pragma warning (Disable: 4507 34)
// Disable warning messages 4507 and 34. # pragma warning (once: 4385) // only send a warning once
# Pragma warning (error: 164) // warning 164 as an error report
For warning numbers related to code generation and greater than 4699, this warning Compilation instruction is only valid when it is placed outside the function definition. If the warning number is greater than 4699 or used in the function body, this compilation instruction is ignored. The following example shows the correct position of the Instruction for disabling warning compilation, and then restores the generation of a warning message generated by a code.

Int;
# Pragma warning (Disable: 4705)
Void func ()
{
A;
}
# Pragma warning (default: 4705)
The warning Compilation instruction also supports the following syntax:
# Pragma warning (push [, N])
# Pragma warning (POP)
N indicates the warning level (1 to 4 ).
The compilation instructs warning (push) to store the current warning status of all warnings. Compile the instruction warning (push, n) to store the current warning status of all warnings and set the global warning level to n.
The compilation instructs warning (POP) to bring up the warning status of the last push into the stack. Any change 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)
At the end of this Code, pop restores all warning States (including 4705, 4706, and 4707) as its warning status at the beginning of the Code.
When writing the header file, you can use push and pop to ensure that the changes in the warning status will not affect the correct compilation of the header. Generally, push is used at the beginning of the header and pop is used at the end. For example, there is a header that is not fully compiled at Warning Level 4. The following code changes the warning level to 3 and restores the original warning level before the end of the header:

# Pragma warning (push, 3)
// Description/Definition
# Pragma warning (POP)

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.