HP C Programmer's Guide (92434-90009)

Chapter 5 139
Programming for Portability
Porting to ANSI Mode HP C
struct s x;
{
/* Function body using the old method for
declaring function parameter types
*/
}
int new_way(struct s x)
{
/* Function body using the new method for
declaring function parameter types
*/
}
/* The functions "old_way" and "new_way" are
both called later on in the program.
*/
old_way(1); /* This call compiles without complaint. */
new_way(1); /* This call gives an error. */
In this example, the function new_way gives an error because the value being passed to
it is of type int instead of type struct
x.
More efficient parameter passing in some cases. Parameters of type float are not
converted to double. For example:
void old_way(f)
float f;
{
/* Function body using the old method for
declaring function parameter types
*/
}
void new_way(float f)
{
/* Function body using the new method for
declaring function parameter types
*/
}
/* The functions "old_way" and "new_way" are
both called later on in the program.
*/
float g;
old_way(g);
new_way(g);
In the above example, when the function old_way is called, the value of g is converted
to a double before being passed. In ANSI mode, the old_way function then converts the
value back to float. When the function new_way is called, the float value of g is passed
without conversion.
Automatic conversion of function arguments, as if by assignment. For example, integer
parameters may be automatically converted to floating point.
/* Function declaration using the new method