HP C Programmer's Guide (92434-90009)

Chapter 5 133
Programming for Portability
General Portability Considerations
unsigned int remainder:20;
};
In this struct declaration, the assignment of data space for c must be aligned so it doesn't
violate a byte boundary, which is the normal alignment of unsigned char. Consequently,
two undeclared bits of padding are added by the compiler so that c is aligned on a byte
boundary. sizeof(struct foo2) returns 6 (bytes) on Series 300/400, and 8 on Series
700/800. Note, however, that on Domain systems or when using #pragma HP_ALIGN
NATURAL, which uses Domain bit-field mapping, 4 is returned because the char bit-fields
are considered to be ints.)
Bit-fields on HP-UX systems cannot exceed the size of the declared type in length. The
largest possible bit-field is 32 bits. All scalar types are permissible to declare bit-fields,
including enum.
Enum bit-fields are accepted on all HP-UX systems. On Series 300/400 in compatibility
mode they are implemented internally as unsigned integers. On Series 700/800, however,
they are implemented internally as signed integers so care should be taken to allow
enough bits to store the sign as well as the magnitude of the enumerated type. Otherwise
your results may be unexpected. In ANSI mode, the type of enum bit-fields is signed int
on all HP-UX systems.
Floating-Point Exceptions
HP C on Series 700/800, in accordance with the IEEE standard, does not trap on floating
point exceptions such as division by zero. By contrast, when using HP C on Series 300/400,
floating-point exceptions will result in the run-time error message Floating exception
(core dumped). One way to handle this error on Series 700/800 is by setting up a signal
handler using the signal system call, and trapping the signal SIGFPE. For details, see
signal(2), signal(5), and "Advanced HP-UX Programming" in HP-UX Linker and Libraries
Online User Guide.
For full treatment of floating-point exceptions and how to handle them, see HP-UX
Floating-Point Guide.
Integer Overflow
In HP C, as in nearly every other implementation of C, integer overflow does not generate
an error. The overflowed number is "rolled over" into whatever bit pattern the operation
happens to produce.
Overflow During Conversion from Floating Point to Integral Type
HP-UX systems will report a floating exception - core dumped at run time if a
floating point number is converted to an integral type and the value is outside the range of
that integral type. As with the error described previously under "Floating Point
Exceptions," a program to trap the floating-point exception signal (SIGFPE) can be used.
See signal(2) and signal(5) for details.