Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Inline initiali...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 25140 of 28006
Post > Topic >>

Inline initialization of a struct containing a string array

by "Antti Karanta" <firstname.lastname@[EMAIL PROTECTED] > Mar 27, 2008 at 12:37 PM

Hi!

   Is it possible to inline initialize a struct whose one member is a st=
ring
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[] =3D {
     { { "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 mai=
n
(i.e. just myfoos[0].x =3D ptrToFirstStrArray ; // ...), but that's not =
very  =

pretty...



          .::Antti::.



   Ps. I did consider "multistrings", e.g. "hello\0world\0", but that wo=
uld  =

be inconsistent w/ the presentation of array of string values used in  =

other parts of the program.
 




 5 Posts in Topic:
Inline initialization of a struct containing a string array
"Antti Karanta"  2008-03-27 12:37:11 
Re: Inline initialization of a struct containing a string array
Eric Sosman <Eric.Sosm  2008-03-27 10:23:21 
Re: Inline initialization of a struct containing a string array
"Antti Karanta"  2008-03-29 19:33:54 
Re: Inline initialization of a struct containing a string array
Andrey Tarasevich <and  2008-03-27 08:13:46 
Re: Inline initialization of a struct containing a string array
"Antti Karanta"  2008-03-29 19:32:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 11:52:16 CST 2008.