c++ - Is using #pragma warning push/pop the right way to temporarily alter warning level? -


once in while it's difficult write c++ code wouldn't emit warnings @ all. having warnings enabled idea. necessary disable warnings around specific construct , have them enables in other pieces of code.

i've seen 2 ways of doing far.

the first 1 use #pragma warning( push ) , #pragma warning( pop ):

 #pragma warning( push )  #pragma warning( disable: thatwarning )  //code thatwarning here  #pragma warning( pop ) 

the second use #pragma warning( default ):

 #pragma warning( disable: thatwarning )  //code thatwarning here  #pragma warning( default: thatwarning ) 

the problem see in second variant discards original warning level - warning might have been off before or warning level might have been altered. using default discard alterations.

the first approach looks clean. there problems it? there better ways achieve same?

the first method best way it, imo. know of no problems it.

simply bear in mind #pragma compiler specific don't expect work on every compiler out there :)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -