HP C Programmer's Guide (92434-90009)

Chapter 5 135
Programming for Portability
General Portability Considerations
f may be evaluated before or after g, but g(x) will always be multiplied by 5 before it is
added to f(x). Since there is no C standard for order of evaluation of expressions, you
should avoid relying on the order of evaluation when using functions with side effects or
using function calls as actual parameters. You should use temporary variables if your
program relies upon a certain order of evaluation.
Variable Initialization
On some C implementations, auto (non-static) variables are implicitly initialized to 0.
This is not the case on HP-UX and it is most likely not the case on other implementations
of UNIX. Don't depend on the system initializing your local variables; it is not good
programming practice in general and it makes for nonportable code.
Conversions between unsigned char or unsigned short and int
All HP-UX C implementations, when used in compatibility mode, are unsigned
preserving. That is, in conversions of unsigned
char or unsigned short to int, the conversion process first converts the number to an
unsigned int. This contrasts to some C implementations that are value preserving
(that is, unsigned
char terms are first converted to char and then to int before they are used in an
expression).
Consider the following program:
main()
{
int i = -1;
unsigned char uc = 2;
unsigned int ui = 2;
if (uc > i)
printf("Value preserving\n");
else
printf("Unsigned preserving\n");
if (ui < i)
printf("Unsigned comparisons performed\n");
}
On HP-UX systems in compatibility mode, the program will print:
Unsigned preserving
Unsigned comparisons performed
In contrast, ANSI C specifies value preserving; so in ANSI mode, all HP-UX C compilers
are value preserving. The same program, when compiled in ANSI mode, will print:
Value preserving
Unsigned comparisons performed
Temporary Files ($TMPDIR)
All HP-UX C compilers produce a number of intermediate temporary files for their private