NO

Author Topic: Anonymous structures + unions wanted :)  (Read 3092 times)

Gerome

  • Guest
Anonymous structures + unions wanted :)
« on: September 17, 2006, 07:11:47 PM »
Hello Pelle!

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

Code: [Select]

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

  • Guest
Anonymous structures + unions wanted :)
« Reply #1 on: September 17, 2006, 08:55:35 PM »
PellesC already supports this, at least my copy does :)

Mike H.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Anonymous structures + unions wanted :)
« Reply #2 on: September 17, 2006, 10:41:52 PM »
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

  • Guest
Anonymous structures + unions wanted :)
« Reply #3 on: September 18, 2006, 12:50:57 AM »
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 :)