Export (0) Print
Expand All
Expand Minimize
0 out of 2 rated this helpful - Rate this topic

Compiler Error C2229

Error Message

type 'identifier' has an illegal zero-sized array

A member of a structure or bit field contains a zero-sized array that is not the last member.

Because you can have a zero sized array as the last member of the struct, you must specify its size when you allocate the struct.

If the zero sized array is not the last member of the struct, the compiler can't calculate the offset for the remaining fields.

The following sample generates C2229:

// C2229.cpp
struct S {
   int a[0];  // C2229  zero-sized array
   int b[1];

struct S2 {
   int a;
   int b[0];

int main() {
   // allocate 7 elements for b field
   S2* s2 = (S2*)new int[sizeof(S2) + 7*sizeof(int)];
   s2->b[6] = 100;
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.