I'm going to write up some notes about various modern UNIX compilers, first up is the HP-UX compiler.
The HP-UX C/C++ compiler is currently at version A.06.27, last updated in 2012. Since the creation of version 6, it seems to only have had a few tweaks made to it. For example, it lacks many new C++ features.
Nevertheless, it has some useful warning options that can help with migrating code to 64-bit goodness.
Compiler versions
$ cc -V
cc: HP C/aC++ B3910B A.06.27 [May 22 2012]
$ aCC -V
aCC: HP C/aC++ B3910B A.06.27 [May 22 2012]
A very simple example:
#include stdio.h
#include stdlib.h
#include string.h
int main(int argc, char *argv[])
{
int len;
char str[] = "Hello world, is this string okay?";
len = strlen(str);
printf("strlen is %d\n", strlen(str));
return 0;
}
Interesting options that could help us
+w64bit - Enables warnings that help detection of potential problems in converting 32-bit applications to 64-bit
+wlint - Enables several warnings in the compiler that provide lint like functionality
+wperfadvice - Enables performance advisory messages.
+wsecurity - Enables compile-time diagnostics for potential security violations
+w - Warns about all questionable constructs
Some of these options are lint-like, some are useful performance tips, others help with code porting issues.
A normal compile gives no warning in the above example, but if we add these warning flags we get extra output:
$ cc strlen_example.c -o strlen_example +w64bit
"strlen_example.c", line 11: warning #4229-D: 64 bit migration: conversion
from "size_t" to "int" may truncate value
len = strlen(str);
^
more:
$ cc strlen_example.c -o strlen_example +w
"strlen_example.c", line 11: remark #4229-D: 64 bit migration: conversion from
"size_t" to "int" may truncate value
len = strlen(str);
^
"strlen_example.c", line 13: remark #2181-D: argument is incompatible with
corresponding format string conversion
printf("strlen is %d\n", strlen(str));
^
"strlen_example.c", line 8: remark #2550-D: variable "len" was set but never
used
int len;
^
Larger example output from some code that deals with large files:
"MyLargeFile.c", line 231: warning #4298-D: addition result could be truncated before cast to bigger sized type
"MyLargeFile.c", line 321: warning #4229-D: 64 bit migration: conversion from "size_t" to "int" may truncate value
"MyLargeFile.c", line 723: warning #4298-D: multiply result could be truncated before cast to bigger sized type
"MyLargeFile.c", line 3263: warning #4229-D: 64 bit migration: conversion from "unsigned long" to "unsigned int" may truncate value
"MyLargeFile.c", line 2423: warning #4229-D: 64 bit migration: conversion from "size_t" to "int" may truncate value
"MyLargeFile.c", line 3478: warning #4229-D: 64 bit migration: conversion from "unsigned long" to "int" may truncate value
"MyLargeFile.c", line 5134: warning #4229-D: 64 bit migration: conversion from "long" to "int" may truncate value
"MyLargeFile.c", line 5692: warning #4231-D: 64 bit migration: conversion between types of different sizes has occurred (from "int" to "void *" )
As you can see, the compiler can spot quite a few issues with this code that you might want to consider carefully when making a real 64-bit pure aware application.
External links:
HP aC++/HP C Online Programmer's Guide
Command-Line Options