HP C Programmer's Guide (92434-90009)

150 Chapter5
Programming for Portability
Porting between HP C and VMS C
Porting between HP C and VMS C
The C language itself is easy to port from VMS to HP-UX for two main reasons:
There is a high degree of compatibility between HP C and other common industry
implementations of C as well as within the HP-UX family.
The C language itself does not consider file manipulation or input/output to be part of
the core language. These issues are handled via libraries. Thus, C avoids some of the
thorniest issues of portability.
In most cases, HP C (in compatibility mode) is a superset of VMS C. Therefore, porting
from VMS to HP-UX is easier than porting in the other direction. The next several
subsections describe features of C that can cause problems in porting.
Core Language Features
Basic data types in VMS have the same general sizes as their counterparts on HP-UX.
In particular, all integral and floating-point types have the same number of bits.
structs and unions do not necessarily have the same size because of different
alignment rules.
Basic data types are aligned on arbitrary byte boundaries in VMS C. HP-UX
counterparts generally have more restrictive alignments.
Type char is signed by default on both VMS and HP-UX.
The unsigned adjective is recognized by both systems and is usable on char, short,
int, and long. It can also be used alone to refer to unsigned int.
Both VMS and HP-UX support void and enum data types although the allowable uses of
enum vary between the two systems. HP-UX is generally less restrictive.
The VMS C storage class specifiers globaldef, globalref, and globalvalue have no
direct counterparts on HP-UX or other implementations of UNIX. On HP-UX, variables
are either local or global, based strictly on scope or static class specifiers.
The VMS C class modifiers readonly and noshare have no direct counterparts on
HP-UX.
structs are packed differently on the two systems. All elements are byte aligned in
VMS whereas they are aligned more restrictively on the different HP-UX architectures
based upon their type. Organization of fields within the struct differs as well.
Bit-fields within structs are more general on HP-UX than on VMS. VMS requires that
they be of type int or unsigned whereas they may be any integral type on HP-UX.
Assignment of one struct to another is supported on both systems. However, VMS
permits assignment of structs provided the types of both sides have the same size.
HP-UX is more restrictive because it requires that the two sides be of the same type.
VMS C stores floating-point data in memory using a proprietary scheme. Floats are
stored in F_floating format. Doubles are stored either in D_floating format or
G_floating format. D_floating format is the default. HP-UX uses IEEE standard