Feature-request: Possibility of transparent unions in structs

Joe Buck jbuck@synopsys.COM
Mon Mar 27 09:36:00 GMT 2000


> The question: Is there a way to make the union identifier transparent to the
> structure, such that the members of the union can be referenced from the
> context of the structure?

In C++, there is.  It's called anonymous unions.  For your example, you
would write

struct foo {
	int type;
	union {
		int id;
		int *data;
		char *string;
	}
};

and then, given
	foo *bar;

you can write bar->id, bar->data, bar->string, bar->type.

> Can anyone tell me if this feature exists currently in GCC (as a C extension),
> or if possible, can be added to gcc 2.96 / 3.0?

It does not exist as a C extension.  I'm not convinced that it is a good
idea to move C++ features into the C front end as extensions on an ad hoc
basis, though I suppose some folks think we set a precedent when C++
comments were allowed.



More information about the Gcc mailing list