HP aC++/HP C A.06.20 Programmer's Guide
Diagnostic Pragmas
The following are the diagnostic pragmas supported by the HP aC++ compiler.
diag_xxx Pragmas
#pragma diag_suppress message1 message2 ...
#pragma diag_warning message1 message2 ...
#pragma diag_error message1 message2 ...
#pragma diag_default message1 message2 ...
Command-line options help you generate diagnostic messages for the entire build or
for a specific source file. The diag pragmas let you manage warnings for a specific
region within a source file. The use of #pragma diag_suppress within the source
code disables generation of the specified warning messages after the pragma in the
source file. The pragma diag_defaultrestores the default handling for the specified
diagnostic messages. Similarly, diag_warning enables generation of the specified
diagnostic messages, and diag_error converts a warning to an error.
Only diagnostics above 2000 are affected. This pragma will not affect the lower
numbered diagnostics issued by the compiler's driver program.
Refer to the HP Code Advisor documentation for additional information.
The following example disables warning #2549-D locally:
int i;
#pragma diag_suppress 2549
printf ("i = %d\n", i);
#pragma diag_default 2549
Other Pragmas
The following are additional pragmas supported on the HP aC++ compiler:
assert Pragma
#pragma assertnon-zero(constant-expression)”string”
When the compiler encounters this directive, it evaluates the expression. If the expression
is zero, the compiler generates a message that contains the specified string and the
compile-time constant expression.
For example:
#pragma assert non_zero(sizeof(a) == 12) "a is the wrong size"
In this example, if the compiler determines that sizeof(a) is not 12, the following
diagnostic message is output:
"foo.c", line 10: error #2020: The assertion "(sizeof(a) == 12)" was not true.
a is the wrong size
Consider the following example that verifies both the size of a struct and the offset
of one of its elements:
Diagnostic Pragmas 137