Anonymous structures + unions wanted :)

Started by Gerome, September 17, 2006, 07:11:47 PM

Previous topic - Next topic

Gerome

Hello Pelle!

It'd be nice to have anonymous structures + unions supported into PellesC :)


include <stdio.h>

typedef struct t_test {
  int a;
  union {
     int b;
     struct {
        int c;
        int d;
     };
     struct {
        int e;
        int f;
     };
     int g;
  };
} T_TEST;


int main(void)
{
T_TEST t;
  t.a = 1;
  t.b = 2;
  t.c = 3;
  t.d = 4;
  t.e = 5;
  t.f = 6;
  t.g = 7;
  printf("%d %d %d %d %d %d %d sz %d\n", t.a, t.b, t.c, t.d, t.e, t.f, t.g,
sizeof(t));
getchar();
}


Should give :
1 7 7 6 7 6 7 sz 12

Thanks

Mikehg

PellesC already supports this, at least my copy does :)

Mike H.

Pelle

Yes - the snippet is non-standard in every way, but if you enable Microsoft extension (the /Ze compiler option) you should get what you want...
/Pelle

Gerome

Hi,
Quote from: "Pelle"Yes - the snippet is non-standard in every way, but if you enable Microsoft extension (the /Ze compiler option) you should get what you want...

Thanks Pelle!
Non standard does not always means bad :)
I love unnamed structs & unions :)