HP C Programmer's Guide (92434-90009)

Chapter 5 137
Programming for Portability
Porting to ANSI Mode HP C
Porting to ANSI Mode HP C
This section describes porting non-ANSI mode HP C programs to ANSI C. Specifically, it
discusses:
Compile line options.
ANSI C name spaces.
Differences that can lead to porting problems.
ANSI Mode Compile Option (-Aa)
To compile in ANSI C mode, use the -Aa compile time option. By default, HP C compilers
use non-ANSI mode; that is HP C compilers use the language definition defined in
Kernighan and Ritchie's The C Programming Language, First Edition, as well as selected
BSD (Berkeley Software Distribution) extensions. ANSI mode may become the default in a
future release.
The -w and +e options should not be used at compile time for true ANSI compliance. These
options suppress warning messages and allow HP C extensions that are not ANSI
conforming.
HP C Extensions to ANSI C (+e)
There are a number of HP C extensions enabled by the +e option in ANSI mode:
Long pointers.
Dollar sign character $ in an identifier.
Compiler supplied defaults for missing arguments to intrinsic calls (For example
FOPEN(
"filename",fopt,,rsize
), where ,, indicates that the missing
aopt
parameter is automatically supplied with default values.)
Sized enumerated types: char enum, short enum, int enum, and long enum.
Long long integer type. Note, the long long data type is only available in HP C Series
700/800.
These are the only HP C extensions that require using the +e option.
When coding for portability, you should compile your programs without the +e command
line option, and rewrite code that causes the compiler to generate messages related to HP
C extensions.
const and volatile Qualifiers
HP C supports the ANSI C const and volatile keywords used in variable declarations.
These keywords qualify the way in which the compiler treats the declared variable.
The const qualifier declares variables whose values do not change during program
execution. The HP C compiler generates error messages if there is an attempt to assign a
value to a const variable. The following declares a constant variable pi of type float with