HP C/iX Reference Manual (31506-90011)
Chapter 5 63
Expressions
Function Calls
Thus, for safety, it is highly advisable to use prototypes wherever possible.
In both cases, arrays of type T are converted to pointers to type T, and functions are
converted to pointers to functions.
Within a function, the formal parameters are lvalues that can be changed during the
function execution. This does not change the arguments as they exist in the calling
function. It is possible to pass pointers to objects as arguments. The called function can
then reference the objects indirectly through the pointers. The result is as if the objects
were passed to the function using call by reference. The following swap function illustrates
the use of pointers as arguments. The swap() function exchanges two integer values:
void swap(int *x,int *y)
{
int t;
t = *x;
*x = *y;
*y=t;
}
To swap the contents of integer variables i and j, you call the function as follows:
swap(i, j);
Notice that the addresses of the objects (pointers to int) were passed and not the objects
themselves.
Because arrays of type T are converted into pointers to type T, you might think that arrays
are passed to functions using call by reference. This is not actually the case. Instead, the
address of the first element is passed to the called function. This is still strictly call by
value since the pointer is passed by value. Inside the called function, references to the
array via the passed starting address, are actually references to the array in the calling
function. Arrays are not copied into the address space of the called function.
All functions are recursive both in the direct and indirect sense. Function A can call itself
directly or function A can call function B which, in turn, calls function A. Note that each
invocation of a function requires program stack space. For this reason, the depth of
recursion depends upon the size of the execution stack.