This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: TODO: egcs-g++
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.