HP C/iX Reference Manual (31506-90011)
Chapter 3 43
Data Types and Declarations
Declarators
• If the array is a formal parameter in a function definition.
• If the array declaration contains an initializer.
• If the array declaration has external linkage and the definition (in another translation
unit) that actually allocates storage provides the dimension.
Following are examples of array declarations:
int x[10]; /* x: Array of 10 integers */
float y[10][20]; /* y: Matrix of 10x20 floats */
extern int z[ ]; /* z: External integer array of undefined */
/* dimension */
int a[ ]={2,7,5,9}; /* a: Array of 4 integers */
int m[ ][3]= { /* m: Matrix of 2x3 integers */
{1,2,7},
{6,6,6} };
Note that an array of type T that is the formal parameter in a function definition has been
converted to a pointer to type T. The array name in this case is a modifiable lvalue and can
appear as the left operand of an assignment operator. The following function will clear an
array of integers to all zeros. Note that the array name, which is a parameter, must be a
modifiable lvalue to be the operand of the ++ operator.
void clear(a, n)
int a[]; /* has been converted to int * */
int n; /* number of array elements to clear */
{
while(n) /* for the entire array */
*a = 0; /* clear each element to zero */
}
Function Declarators
If D is a declarator, and T is some combination of type specifiers and storage class specifiers
(such as int), then the declaration
TD(
parameter-type-list
)
or
TD(
[identifier-list]
)
declares D to be a function returning type T. A function can return any type of object except
an array or a function. However, functions can return pointers to functions or arrays.
If the function declarator uses the form with the
parameter-type-list
, it is said to be in
"prototype" form. The parameter type list specifies the types of, and may declare identifiers
for, the parameters of the function. If the list terminates with an ellipsis (,…), no
information about the number of types of the parameters after the comma is supplied. The
special case of void as the only item in the list specifies that the function has no
parameters.
If a function declarator is not part of a function definition, the optional
identifier-list
must be empty.
Function declarators using prototype form are only allowed in ANSI mode.