Are zero-length variable length arrays allowed/well defined?

c, c99

Solution

No, zero-length arrays are explicitly prohibited by C language, even if they are created as VLA through a run-time size value (as in your code sample).

6.7.5.2 Array declarators

...

5 If the size is an expression that is not an integer constant expression: if it occurs in a declaration at function prototype scope, it is treated as if it were replaced by *; otherwise, each time it is evaluated it shall have a value greater than zero.

Problem

I'm programming in C99 and use variable length arrays in one portion of my code. I know in C89 zero-length arrays are not allowed, but I'm unsure of C99 and variable length arrays. In short, is the following well defined behavior? ``` int main() { int i = 0; char array[i]; return 0; } ```

Original source