Re: [patch] ptype: show members of an unnamed struct inside an union

Joel Brobecker
2007-08-29T04:36:44Z

> > Does this case actually make any sense? I don't think you can access
> > this union in your C program either, or can you?
>
> GCC supports anonymous unions. There's a test for it in the GDB
> testsuite, too.

But how can you access this union if the field doesn't have a name?
More precisely, using the example that Carlos sent:

struct my_page {
union {
struct { int mapping; };
};
};

How do you access the union? That's why I gave the union field a name
"u" as follow:

struct my_page {
union {
struct { int mapping; };
} u;
};

So that I can reference it using "my_page.u".

Just to be clear, I am not trying to object to the idea of enhancing
GDB for such situations, I'm just trying to understand whether these
situations correspond to something actually useful. I've seen this
being used in the past, when some fields were inserted as a way of
inserting some padding. I don't think it's really essential in that
case to show the actual description of the padding, or maybe it is?

--
Joel