Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: made some significant edits to the introductory paragraph; please review

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 references a pointer to an array of indeterminite indeterminate size.

The C standard, since 1999 Since C99, C 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.

...

... 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.

Consequently, an array declaration that serves as a function argument may have an index that is a variable or an expression. This does not indicate that the argument indicates a VLA, as the The array argument is demoted to a pointer. But it , and is consequently not a VLA. Conformant array parameters can be used by developers to indicate the expected bounds of the array. This information may be used by compilers, or it may be ignored. But However, such declarations are useful to other developers as they serve to document relationships between array sizes and other relevant variables. Furthermore, the pointers. This information can also be used by static analysis tools to diagnose potential defects.

Code Block
int f(size_t n, int a[n]);  // documents a relationship between n and a

...

Code Block
double maximum(int n, int m, double a[n][m]);
double maximum(int n, int m, double a[*][*]);
double maximum(int n, int m, double a[ ][*]);
double maximum(int n, int m, double a[ ][m]);

...

Noncompliant Code Example

...