You copied the Doc URL to your clipboard.

Controlling compiler diagnostic messages with pragmas

Pragmas let you suppress, enable, or change the severity of specific diagnostic messages from within your code. For example, you can suppress a particular diagnostic message when compiling one specific function.


You can also use options to suppress or change the severity of messages, but the change applies for the entire compilation.

Diagnostic messages use the pragma state in place at the time they are generated. If you use pragmas to control a message in your code, you must be aware of when that message is generated. For example, the following code is intended to suppress the diagnostic message 177 (“Function was declared but never referenced”) for the dummy function:

#include <stdio.h>
#pragma push
#pragma diag_suppress 177
static int dummy(void)
    printf("This function is never called.");
    return 1;
#pragma pop
     printf("Hello world!\n");

The intention of the programmer is to push the current pragma state to the stack, suppress diagnostic message 177 when compiling the dummy function, then restore the original pragma state before continuing with compilation.

However, message 177 is only generated after all functions have been processed. Therefore, the message is generated after pragma pop restores the pragma state, and message 177 is not suppressed.

Removing pragma push and pragma pop would correctly suppress message 177, but would suppress messages for all unreferenced functions rather than just the dummy function.