I'm using anonymous nested structs extensively for grouping related items, but I consider the extra field name a feature, not something that should be hidden:<p><a href="https://github.com/floooh/sokol-samples/blob/bfb30ea00b5948f2029c7dd228cf30de08b8036c/sapp/shdfeatures-sapp.c#L136-L165" rel="nofollow">https://github.com/floooh/sokol-samples/blob/bfb30ea00b5948f...</a><p>(also note the 'inplace initialization' which follows the state struct definition using C99's designated initialization)
The result is uglier and less maintainable than a pair of macros. Or just stop trying to hide syntax. This is ultimately on the same level as typedefing pointers.
Doesn’t matter for C, but in C++ this could make your contexpr functions UB since you can only use one member of a union in constexpr contexts (the “active” member).
Bleurgh. I have a deep soft spot for C, and I'm known to get twisted pleasure from using obscure language features in new ways to annoy people, but this is a level of abuse that even I can't get behind. If you need namespacing, use C++. As much as I love C, it's terrible for large projects.
This is probably a terrible idea, remember that if you have written one member of a union, all other members remain public, yet accessing any of them in any way is undefined behaviour. This is made way worse by most compilers mostly choosing to let you do what you think it will. They just dont guarantee they always will or in all cases.