Why is zero-length array allowed only if it's heap allocated?

Viewed 4429

I notice that it's not allowed to create non-heap allocated arrays of zero length.

// error: cannot allocate an array of constant length zero
char a[0];

I also notice that it's allowed to create heap allocated arrays of zero length.

// this is okay though
char *pa = new char[0];

I guess they're both guaranteed by the Standard (I don't have a copy of the Standard at hand). If so, why are they so different? Why not just allow a zero-length array on stack (or vice versa)?

5 Answers
Related