pragma warning push[.n] / pop [from msdn]

Push and Pop

The warning pragma also supports the following syntax.

#pragma warning( push [ ,n ] )

#pragma warning( pop )

Where n represents a warning level (1 through 4).

The pragma warning( push ) stores the current warning state for every warning. The pragma warning( push, n) stores the current state for every warning and sets the global warning level to n.

The pragma warning( pop ) pops the last warning state pushed onto the stack. Any changes that you made to the warning state between push and pop are undone. 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 the state of every warning (includes 4705, 4706, and 4707) to what it was at the start of the code.

When you write header files, you can use push and pop to guarantee that warning-state changes made by a user do not prevent the headers from compiling correctly. Use push at the start of the header and pop at the end. For example, if you have a header that does not compile cleanly at warning level 4, the following code would change the warning level to 3 and then restore the original warning level at the end of the header.

#pragma warning( push, 3 )
// Declarations/definitions
#pragma warning( pop ) 
 
即保存及恢复当前warning们的状态
 
Ref: http://msdn.microsoft.com/en-us/library/2c8f766e.aspx

转载于:https://www.cnblogs.com/justin_s/archive/2011/12/23/2299370.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值