HP C/aC++ Version 6 Features to Improve Developer Productivity

8
# disable warning: statement is unreachable
+W2111
$ cc +opts warnings_config +wlint -c uninit.c
"uninit.c", line 6: warning #3348-D: declaration hides variable "i"
(declared at line 3)
int i;
^
"uninit.c", line 9: error #2549-D: variable "i" is used before its value
is set
if (i) j = 3;
^
1 error detected in the compilation of "uninit.c".
#pragma diag_suppress|diag_warning|diag_error NNNN
#pragma diag_default NNNN
Command line options provide control of diagnostics emission for the entire build or for a specific
source file. There are several pragmas which allow the user to control warnings for a specific
region within a source file. The use of #pragma diag_suppress disables generation of warning
N after the pragma in the source file. The pragma diag_default restores the default handling for
diagnostic N. Similarly, diag_warning enables emission of a diagnostic and diag_error
converts a warning to an error.
Runtime Checking
In addition to compile time diagnostics, the HP compilers provide several different +check options
to detect some types of errors at runtime.
Advantages of runtime checks in comparison to compile time diagnostics
Failed runtime checks always indicate a real problem. There are no false positives except
for the UMR check (enabled with +check=bounds:pointer +check=uninit).
Can help detect several hard to catch defects like stack overflow or out-of-bounds accesses
that may not be possible with compile time diagnostics.
Developer does not have to analyze and fix warnings. Action needs to be taken only when a
runtime check fails.
Disadvantages of runtime checks
Runtime checks slow down the user program due to additional instrumentation that is
added. In general, they should be used only during development (debug builds) and not for
released software (production builds).
Runtime checks do not cover all paths in the application. Compile time diagnostics can
analyze and cover all paths in the source.
Compile time diagnostics detect problems earlier and with less overhead.
+check=all|none|bounds|globals|lock|malloc|stack|thread|truncate|uninit
The +check=xxx
options provide runtime checks to detect many common coding errors in the user
program. These options introduce additional instructions for runtime checks that may significantly
slow down the user program.
By default, a failed check will result in the program aborting at the end of
execution at runtime. In most cases, an error message and a stack trace will be emitted to
stderr before
program termination.
The environment variable
RTC_NO_ABORT can be set to 0, 1, or 2 to change the behavior of failed runtime
check: