Some warning messages can be disabled by using the warning
disable
pragma.
This pragma will only affect warnings that are produced by the parser or the code generator; i.e., errors directly associated with C code. The position of the pragma is only significant for the parser; i.e., a parser warning number can be disabled for one section of the code to target specific instances of the warning. Specific instances of a warning produced by the code generator cannot be individually controlled and the pragma will remain in force during compilation of the entire C program, even across modules.
Those warnings that have been disabled can be preserved and recalled using
the warning push
and warning pop
pragmas. The
warning push
and warning pop
pragmas can be
nested.
The following example normally produces the warning associated with
assignment of a const
object address to a pointer to non-const objects
(359).
int readp(int * ip) {
return *ip;
}
const int i = 'd';
int main(void) {
unsigned char c;
#pragma warning disable 359
readp(&i);
#pragma warning enable 359
}
This same effect would be observed using the following code.
#pragma warning push
#pragma warning disable 359
readp(&i);
#pragma warning pop
Here, the state of the messaging system is saved by the warning
push
pragma. Warning 359 is disabled, then after the source code which triggers
the warning, the state of the messaging system is retrieved by using the warning
pop
pragma.