If you compile with gcc -pedantic
, you'll get a warning message:
warning: ISO C forbids zero-size array [-Wpedantic]
The latest draft of the C standard, N1570, section 6.7.6.2 (Array declarators) paragraph 1 says:
If the expression is a constant expression, it shall have a value
greater than zero.
This is part of a constraint, so char[0]
is a constraint violation, requiring a diagnostic from any conforming C compiler.
(It's not 100% clear that that particular clause applies to the type name char[0]
in the absence of a declared object, but the general idea is that standard C does not support zero-length arrays.)
gcc supports zero-sized arrays as an extension, documented here.