From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andi Kleen To: Jason Merrill , Andi Kleen Cc: Alexandre Oliva , egcs@cygnus.com, ildar@faki-campus.mipt.ru Subject: Re: TODO: egcs-g++ Date: Sun, 11 Apr 1999 02:50:00 -0000 Message-id: <19990411114929.A18034@kali.munich.netsurf.de> References: X-SW-Source: 1999-04/msg00377.html On Sun, Apr 11, 1999 at 10:40:03AM +0200, Jason Merrill wrote: > Would someone explain to me what anonymous structs are good for? It seems > like a totally pointless extension. It is a nice way to short cut the #define mazes one often sees, e.g. struct bla { // ... union { struct { int a,b; } A; int c; } blub; }; #define bla_a blub.A.a #define bla_b blub.A.b #define bla_c bla.c Another use would be "poor man's inheritance" in C: struct node { struct node *prev, *next; }; struct bla { struct node; int val; }; Now you can walk the bla list directly via ->next and ->prev points, without playing macro games, or having to type the error prone nd.prev/nd.next all the time (ok the cast is still ugly). I have seen these two situations very often in real world code. They are also a nice symetry to anonymous unions in C++; I would guess if you implement one it isn't that hard to implement the other (and anonymous unions are already implemented in G++, but not in GCC) here was a C9x proposal from Ken Thompson that described the rationale for it better than me, but I cannot find it on the super slow WG14 WWW server ATM. The comitee did reject it for some reason though. I think they would be useful, but of course the tradeoff between just another extension and maintainability is up to the maintainers. -Andi -- This is like TV. I don't like TV. From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andi Kleen To: Jason Merrill , Andi Kleen Cc: Alexandre Oliva , egcs@cygnus.com, ildar@faki-campus.mipt.ru Subject: Re: TODO: egcs-g++ Date: Fri, 30 Apr 1999 23:15:00 -0000 Message-ID: <19990411114929.A18034@kali.munich.netsurf.de> References: X-SW-Source: 1999-04n/msg00380.html Message-ID: <19990430231500.MPXgUWTZ2vaBapWB1jNxL6SepMGEaVxlYzRCj8EOk6I@z> On Sun, Apr 11, 1999 at 10:40:03AM +0200, Jason Merrill wrote: > Would someone explain to me what anonymous structs are good for? It seems > like a totally pointless extension. It is a nice way to short cut the #define mazes one often sees, e.g. struct bla { // ... union { struct { int a,b; } A; int c; } blub; }; #define bla_a blub.A.a #define bla_b blub.A.b #define bla_c bla.c Another use would be "poor man's inheritance" in C: struct node { struct node *prev, *next; }; struct bla { struct node; int val; }; Now you can walk the bla list directly via ->next and ->prev points, without playing macro games, or having to type the error prone nd.prev/nd.next all the time (ok the cast is still ugly). I have seen these two situations very often in real world code. They are also a nice symetry to anonymous unions in C++; I would guess if you implement one it isn't that hard to implement the other (and anonymous unions are already implemented in G++, but not in GCC) here was a C9x proposal from Ken Thompson that described the rationale for it better than me, but I cannot find it on the super slow WG14 WWW server ATM. The comitee did reject it for some reason though. I think they would be useful, but of course the tradeoff between just another extension and maintainability is up to the maintainers. -Andi -- This is like TV. I don't like TV.