I\'m beginning to learn about the use of structs in C. It\'s challenging and enjoyable. Needless to say I\'ve encountered a problem I can\'t seem to figure out. I\'m trying to m
Edit
I think I remember now what the problem is. When you declare a struct with a flexible array as it's last member it's doing something completely different than what you think.
struct channelStruct channels[];
is NOT a pointer, it is an in place array which is contiguous with the struct.
The way this is intended to be used is to lay the struct over an existing block memory. For instance, this is useful in networking when you have a packet with variable length data. So you might do something like:
struct mydata {
// various other data fields
int varDataSize;
char data[];
}
When you receive a packet you cast a pointer to the data to a mydata
pointer and then the varDataSize
field tells you how much you've got. Like I said, the thing to remember is that it's all one contiguous block of memory and data
is NOT a pointer.
Old Answer:
I think that's only allow in the C99 standard. Try compiling with the -std=c99
flag.
Also, see this thread, Variable array in struct
Also see this SO post: Flexible array members in C - bad?