I have a c file that starts with a struct I am calling stringtable, looks like this
struct stringtable {
int table[];
int numElements = 15;
};
And I have a header for it that has this typedef
typedef stringtable *stringtable_ref;
When I compile with gcc I get the errors:
expected identifier or ‘(‘ before ‘[‘ token
expected ‘:’ before ‘int’
like I have declared the struct wrong. I have done structs in C like this before so my question is: Am I making a mistake declaring my struct? Does it need to have a tag before the semicolon? Are there only certain places I am allowed to declare a struct?
A flexible array member like
int table[];can only be the last member of astruct(with at least one more member).And you can’t assign a default value to a member in a
structdeclaration, C doesn’t support that.