HP C/iX Reference Manual (31506-90011)

62 Chapter5
Expressions
Function Calls
Function Calls
Function calls provide a means of invoking a function and passing arguments to it.
Syntax
postfix-expression
(
[argument-expression-list]
)
Description
The postfix-expression must have the type "pointer to function returning T." The result of
the function will be type T. Functions can return any type of object except array and
function. Specifically, functions can return structures. In the case of structures, the
contents of the returned structure is copied to storage in the calling function. For large
structures, this can use a lot of execution time.
Although the expression denoting the called function must actually be a pointer to a
function, in typical usage, it is simply a function name. This works because the function
name will automatically be converted to a pointer, as explained in chapter 4.
C has no call statement. Instead, all function references must be followed by parentheses.
The parentheses contain any arguments that are passed to the function. If there are no
arguments, the parentheses must still remain. The parentheses can be thought of as a
postfix call operator.
If the function name is not declared before it is used, the compiler enters the default
declaration:
extern int
identifier
();
Function arguments are expressions. Any type of object can be passed to a function as an
argument. Specifically, structures can be passed as arguments. Structure arguments are
copied to temporary storage in the called function. The length of time required to copy a
structure argument depends upon the structure's size.
If the function being called has a prototype, each argument is evaluated and converted as
if being assigned to an object of the type of the corresponding parameter. If the prototype
has an ellipsis, any argument specified after the fixed parameters is subject to the default
argument promotions described below.
The compiler checks to see that there are as many arguments as required by the function
prototype. If the prototype has an ellipsis, additional parameters are allowed. Otherwise,
they are flagged are erroneous. Also, the types of the arguments must be
assignment-compatible with their corresponding formal parameters, or the compiler will
emit a diagnostic message.
If the function does not have a prototype, then the arguments are evaluated and subjected
to the default argument promotions; that is, arguments of type char or short (both signed
and unsigned) are promoted to type int, and float arguments are promoted to double.
In this case, the compiler does not do any checking between the argument types and the
types of the parameters of the function (even if it has seen the definition of the function).