5.3 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.

Note

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
main(void){
     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.
Related concepts
5.2 Options that change the severity of compiler diagnostic messages
5.4 Prefix letters in compiler diagnostic messages
5.5 Compiler exit status codes and termination messages
5.6 Compiler data flow warnings
Related reference
5.1 Severity of compiler diagnostic messages
9.75 #pragma diag_default tag[,tag,...]
9.76 #pragma diag_error tag[,tag,...]
9.77 #pragma diag_remark tag[,tag,...]
9.78 #pragma diag_suppress tag[,tag,...]
9.79 #pragma diag_warning tag[, tag, ...]
9.92 #pragma pop
9.93 #pragma push
7.41 --diag_error=tag[,tag,...]
7.42 --diag_remark=tag[,tag,...]
7.43 --diag_style=arm|ide|gnu compiler option
7.44 --diag_suppress=tag[,tag,...]
7.45 --diag_suppress=optimizations
7.46 --diag_warning=tag[,tag,...]
7.47 --diag_warning=optimizations
Non-ConfidentialPDF file icon PDF versionARM DUI0375E
Copyright © 2007, 2008, 2011, 2012, 2014 ARM. All rights reserved.