struct dataStruct { const char* s; int num; };
struct Final_struct { int n; dataStruct a[]; };
Now the problem occurs when I try to initialize the Final_struct as followed:
const Final_struct Example[]= {
{100, { {"age", 20}, {"iq", 120}, {"bmi",26} } },
{100, { {"age", 36}, {"iq", 145}, {"bmi",22} }}
};
It’s a c code, and when I try to compile it gives the compiler error :
Fields of the object can not have arrrays of size 0
Any suggestions?
thank you.
dataStruct a[]defines the member of the struct as an array of size0. This is practically useless. You need to specify its size in the definition of thestructbecause the compiler needs to know the size of the entirestructin advance.Or, you can simply declare the field as
dataStruct *aand then the array itself will not be contained in thestruct.