|
|
HP-UX/HP C Compiler: HP C/HP-UX Reference Manual > Chapter 3 Data Types and Declarations Function Definitions |
|
A function definition introduces a new function.
A function definition provides the following information about the function:
Do not confuse definition with declaration, especially in the case of functions. Function definition implies that the above four pieces of information are supplied. Function declaration implies that the function is defined elsewhere. You can declare formal parameters as structures or unions. When the function is called, the calling function"s argument is copied to temporary locations within the called function. All functions in C may be recursive. They may be directly recursive so the function calls itself or they may be indirectly recursive so a function calls one or more functions which then call the original function. Indirect recursion can extend through any number of layers. In function definitions that do not use prototypes, any parameters of type float are actually passed as double, even though they are seen by the body of the function as floats. When such a function is called with a float argument, the float is converted back to float on entry into the function.
In a prototype-style definition, such conversions do not take place, and the float is both passed and accessed in the body as a float. char and short parameters to nonprototype-style function definitions are always converted to type int. This conversion does not take place in prototype-style definitions. In either case, arrays of type T are always adjusted to pointer to type T, and functions are adjusted to pointers to functions. Single dimensioned arrays declared as formal parameters need not have their size specified. If the name of an integer array is x, the declaration is as follows:
For multidimensional arrays, each dimension must be indicated by a pair of brackets. The size of the first dimension may be left unspecified. The storage class of formal parameters is implicitly "function parameter." A further storage class of register is accepted. The following example shows a function that returns the sum of an array of integers.
This is an example of a function definition without prototypes.
Here is an example of a function definition using prototypes.
|
|