HP C Programmer's Guide (92434-90009)

Chapter 5 151
Programming for Portability
Porting between HP C and VMS C
formats which are not compatible with VMS types but which are compatible with most
other industry implementations of UNIX.
VMS C converts floats to doubles by padding the mantissa with 0s. HP-UX uses IEEE
formats for floating-point data and therefore must do a conversion by means of
floating-point hardware or by use of library functions. When doubles are converted to
floats in VMS C, the mantissa is rounded toward zero, then truncated. HP-UX uses
either floating point hardware or library calls for these conversions.
The VMS D_floating format can hide programming errors. In particular, you might
not immediately notice that mismatches exist between formal and actual function
arguments if one is declared float and the counterpart is declared double because the
only difference in the internal representation is the length of the mantissa.
Due to the different internal representations of floating-point data, the range and
precision of floating-point numbers differs on the two systems according to the following
tables:
VMS C identifiers are significant to the 31st character. HP-UX C identifiers are
significant to 255 characters.
register declarations are handled differently in VMS. The register reserved word is
regarded by the compiler to be a strong hint to assign a dedicated register for the
variable. On Series 300/400, the register declaration causes an integral or pointer
type to be assigned a dedicated register to the limits of the system, unless optimization
at level +O2 or greater is requested, in which case the compiler ignores register
declarations. Series 700/800 treats register declarations as hints to the compiler.
If a variable is declared to be register in VMS and the & address operator is used in
conjunction with that variable, no error is reported. Instead, the VMS compiler converts
the class of that variable to auto. HP-UX compilers will report an error.
Type conversions on both systems follow the usual progression found on
implementations of UNIX.
Character constants (not to be confused with string constants) are different on VMS.
Table 5-3. VMS C Floating-Point Types
Format Approximate Range of |x| Approximate Precision
F_floating 0.29E-38 to 1.7E38 7 decimal digits
D_floating 0.29E-38 to 1.7E38 16 decimal digits
G_floating 0.56E-308 to 0.99E308 15 decimal digits
Table 5-4. HP-UX C Floating-Point Types
Format Approximate Range of |x| Approximate Precision
float 1.17E-38 to 3.40E38 7 decimal digits
double 2.2E-308 to 1.8E308 16 decimal digits
long double 3.36E-4932 to 1.19E4932 31 decimal digits