A
Antti Karanta
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 }
} ;
This produces warnings (from mingw gcc) for line w/ "hello" on it:
"initialization from incompatible pointer type"
"excess elements in scalar initializer"
"braces around scalar initializer"
So obviously this is not the way to do it, or I am missing something
here? Is
this possible at all?
It works fine if I define the first struct memeber as char* x[ 3 ] ; but
that
is not what I'm after - I need arbitrary length char* arrays.
As a last resort, I can do the initialization in the beginning of main
(i.e. just myfoos[0].x = ptrToFirstStrArray ; // ...), but that's not very
pretty...
.::Antti::.
Ps. I did consider "multistrings", e.g. "hello\0world\0", but that would
be inconsistent w/ the presentation of array of string values used in
other parts of the program.
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 }
} ;
This produces warnings (from mingw gcc) for line w/ "hello" on it:
"initialization from incompatible pointer type"
"excess elements in scalar initializer"
"braces around scalar initializer"
So obviously this is not the way to do it, or I am missing something
here? Is
this possible at all?
It works fine if I define the first struct memeber as char* x[ 3 ] ; but
that
is not what I'm after - I need arbitrary length char* arrays.
As a last resort, I can do the initialization in the beginning of main
(i.e. just myfoos[0].x = ptrToFirstStrArray ; // ...), but that's not very
pretty...
.::Antti::.
Ps. I did consider "multistrings", e.g. "hello\0world\0", but that would
be inconsistent w/ the presentation of array of string values used in
other parts of the program.