HP C A.06.05 Reference Manual

Data Types and Declarations
Declarators
Chapter 3 57
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 */
}
Variable Length Array
Variable Length Array(VLA) is a part of C99 standards (ISO/IEC 9899:1999). VLA allows the
integer expression delimited by [ and ] in an array declarator to be a variable expression or *.
An identifier whose declaration has such an array declarator is a variably modified (VM) type.
All identifiers having a VM type must be either:
block scope or function prototype scope, if the expression in an array declarator is a
variable expression or
function prototype scope, if the expression is *.
NOTE VLA is supported only in ANSI extended (-Ae) mode.
Arrays declared with the static or extern storage class specifier cannot have a VM type. But a
pointer to an array declared with the static storage class specifier can have a VM type. All
identifiers having a VM type are ordinary identifiers and therefore cannot be the members of
structures or unions.
extern int n;
int A[n]; // Error - file scope VM type
extern int (*p) [n]; // Error - file scope VM type
int B[100]; // OK - file scope but not VM type
void foo(int m, int C[m] // OK - function prototype
// scope VM type
{
typedef int VLA[m] [m]; // OK - block scope VM type
int D[m]; // OK - block scope with VM type
static int E[m]; // Error - static specifier in VM type
extern int F[m]; // Error - extern specifier in VM type
int (*q)[m]; // OK - block scope with VM type
extern int (*r)[m]; // Error - extern specifier in VM type
static int (*s)[m] = &B; // OK - static specifier allowed in VM
// type since ‘s’ is pointer to array
struct tag {