array and structure initialization
steve at whuxk.UUCP
steve at whuxk.UUCP
Tue Jun 14 02:22:52 AEST 1983
In reference to why the statements
struct foo {
char *f_slist[];
int f_code;
}
struct foo foobar = { {"xx", "yy", ""}, 1};
leads to compiler errors, the problem lies with the definition of the foo
structure. The member f_slist cannot be declared as an array of character
pointers in that fashion--it must be given a size. The only places that
such a declaration is allowed (i.e. an array with no explicit dimensions)
is
1. When declaring an array with a list of initializers
(e.g. char *ptrs[] = { "abc", "def", "ghi" };
2. When declaring an externally-referenced array.
3. When declaring a formal parameter array.
If you try adding a dimension to f_slist, then you will find that your
initialization will work correctly.
Steve Kochan
BTL Whippany
More information about the Comp.lang.c
mailing list