9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] initialization of anonymous structs.
@ 2008-12-04 12:07 Gorka Guardiola
  2008-12-04 12:26 ` Gorka Guardiola
  0 siblings, 1 reply; 5+ messages in thread
From: Gorka Guardiola @ 2008-12-04 12:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Say I have a couple of structs like:

typedef struct A A;
typedef struct B B;

struct A
{
      int a1;
      int a2;
};

struct B
{
     A;
     int b1;
     int b2;
};

Now I want to declare a variable of kind B with parts initialized. Is
there anyway to initialize the A inside the B?. I have tried:

B bvar = {
    .a1 2
    .b1 2
};


B bvar = {
    .a1=2
    .b1=2
};

B bvar = {
    .A { .a1=2}
    .b1 2
};

B bvar = {
    .A={ .a1 2}
    .b1 2
};

B bvar = {
    .A={2}
    .b1 2
};

I always get the error that the field does not exist.

I have looked at the code of the compiler
and run it with -di and have not been able to figure out a way to initialize
the anonymous struct.

Am I missing something?. Is there a way to do this?.

--
- curiosity sKilled the cat



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-12-04 15:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-04 12:07 [9fans] initialization of anonymous structs Gorka Guardiola
2008-12-04 12:26 ` Gorka Guardiola
2008-12-04 12:33   ` Sape Mullender
2008-12-04 14:56     ` roger peppe
2008-12-04 15:16       ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).