Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Traditionally C arrays are declared with an index that is either a fixed constant, or empty. An array with a fixed constant index indicates to the compiler how much space to reserve for the array. An array declaration with an empty index is considered an incomplete type, and indicates that the variable indicates a pointer to an array of indeterminite size.

The C standard, since 1999 has permitted array declarations to use extended syntax. The most well-known extension is for variable-length arrays (VLAs). In this case, the array index is a variable, and the size of the array is determined at run-time, rather than compile-time.

Section 6.7.6.1, paragraph 1, summarizes the array index syntax extensions:

In addition to optional type qualifiers and the keyword static, the [ and ] may delimit
an expression or *. If they delimit an expression (which specifies the size of an array), the
expression shall have an integer type. If the expression is a constant expression, it shall
have a value greater than zero. The element type shall not be an incomplete or function
type. The optional type qualifiers and the keyword static shall appear only in a
declaration of a function parameter with an array type, and then only in the outermost
array type derivation.

By the way, one thing that came up for me last week was that we probably ought to mention conformant array parameters. For example,

...