#pragma warning

#pragma warning ... generally in the very beginning of the header file.

1. #pragma warning is valid only for the current file (for .h, for cpp containing it is also effective), but not effective for all files of the whole project. When the file is compiled end, setting it useless.

2. #pragma warning (push) storing the current alarm setting. #pragma warning (push, n) storing the current setting alarms, and alarm level set to n. n is a natural number from 1 to 4.

3. #pragma warning (pop) is pressed into the stack before the alarm recovery. Code after the sentence, on the restoration of warning, any alarm settings, ie between a pair of push and pop made will be lost.

4. #pragma warning (disable: n) will be set to an alarm failure.

5. #pragma warning (default: n) is set to the default alarm.

#pragma warning (push) is to preserve the current compiler warning state;
#pragma warning (POP) is to restore the original state of alert.
For example:
#pragma warning (Push)
#pragma warning (disable: 4705.)
#pragma warning (disable: 4706)
#pragma warning (disable: 4707)
// Some code
#pragma warning (POP)
such Some code compiled code portion when, 4705,4706,4707 three warning does not appear.

1. Place a warning as an error
#pragma warning (error: 6260)
2. a warning will disable the swap
#pragma warning (disable: 6011)
3. will enable a disabled warning
#pragma warning (enable: 6011)

Common #pragma warning (disable: ...), can be written at the beginning of the precompiled header file stdafx.h

#pragma warning (disable: 4996) // use strcpy sprintf the like, rather than having to use the security function and the like provided strcpy_s sprintf_s MS 
#pragma warning (disable 4786) // 4786 is an identifier of long lead warning 
#pragma Once / / this is a more frequently used instructions, this instruction just add at the beginning of the header can be guaranteed a header file is compiled, can replace #ifndef .. #define .. #endif

 

Guess you like

Origin www.cnblogs.com/htj10/p/11567159.html