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

3
Example
$ cat bitfield.c
struct { int bit:1; } s;
void test()
{
s.bit = 1;
}
$ cc -c +wlint bitfield.c
"bitfield.c", line 1: warning #2108-D: signed bit field of
length 1
struct { int bit:1; } s;
^
"bitfield.c", line 5: warning #4251-D: the assignment has an
excessive size for a bit field
s.bit = 1;
^
Other notable examples of warnings enabled with the +wlint option:
Argument is incompatible with formal parameter
Function declared implicitly
Function is re-declared after being called
Type conversion may truncate value
Unsigned value cannot be less than zero
Missing return statement at end of non-void function
Nested comment is not allowed
Signed bitfield of length 1
Memory leak
Potential null pointer dereference
Detection of uncaught exceptions
Uninitialized variables
+w64bit
This option enables warnings that help you detect potential problems in converting 32-bit
applications to 64-bit. The +w64bit option applies both to 32 bit and 64 bit compilers. It is
equivalent to the +M2 option.
Some of the checks performed are:
64bit value is implicitly converted to a 32bit value, e.g. long to int.
Pointer to 4-byte aligned object implicitly converted to a pointer to 8-byte aligned object.
Example
$ cat convert.c
int *int_to_ptr (int i)
{
return (int *)i;
}
$ cc –c +w64bit convert.c
"convert.c", line 3: warning #4231-D: 64 bit migration:
conversion between types of different sizes has occurred
(from "int" to "int * ”)
return (int *)i;
^