C String inside a union inside a structure

How to initialize a structure variable B or C?

typedef struct _A
{
  union
  {
    struct
    {
      int b;
    } B;
    struct
    {
      int c;
    } C;
  } u;
} A;

Something A.u.B *bVar;doesn't seem to work

+3
source share
3 answers

You have to put your structure aside.

typedef struct {
    int b;
} B;
+1
source

typedefcovers only A, not the association or structures defined in it.

typedefcannot be nested this way: each user-defined "type" must have one label, so declaring a type variable A.u.Bis illegal.

+4
source

:

/* Initialise to zero */
A a = {{{0},{0}}};
/* Now set the b to 5 */
a.u.B.b = 5;

, , . , A, A.u, A.u.B, 0 A.u.B.b. A.u.B, , A.u.C, A.u.C.c, .

. . , ...

+3

All Articles