Antti Karanta wrote:
>
>
> Hi!
>
> Is it possible to inline initialize a struct whose one member is a string
> array of arbitrary length (terminated w/ a NULL ptr)? What I mean is
> something like this:
>
>
> typedef struct {
> char** x ;
> int y ;
> } Foo ;
>
> static const Foo myfoos[] = {
> { { "hello", "world", NULL }, 12 },
> { NULL, 0 }
> } ;
Define the arrays first, give them names, and use the
names when you initialize the structs.
static const char* fooArray0[] = {
"hello", "world", NULL };
static const char* fooArray1[] = {
"there", "is", "no", "Cabal", NULL };
static const Foo myfoos[] = {
{ fooArray0, 12 },
{ fooArray1, 42 },
{ NULL, 0 } };
It's not as slick as if you could somehow make the arrays
anonymous, but it works.
--