Declare structs as anonymous within anonymous unions#329
Declare structs as anonymous within anonymous unions#329athre0z merged 2 commits intozyantific:masterfrom
Conversation
|
Under which conditions does this fail to build? It's compiling perfectly fine with gcc both on my local box and the CI. Removing the names will break the code-generation of various bindings -- that's why the structs are named in the first place. |
Are you building it as C11? The issue is including it from a cpp compilation unit. You'll run into |
|
I can keep the struct names but that would require to move them out of the union. |
|
Ah. Yeah, we switched to C11 to permit anonymous unions. Looks like this is an incompatibility between C++ and C11 then, meh. I think we might have to keep the structs named, but move them out of the nesting then instead of removing the names. |
|
Also you mentioned of possibly breaking bindings, how do you bind a type that comes from an anonymous struct/union, is it in C11 accessible from the global scope? I'm not that good with C but I would imagine the type can't be accessed, at least not in Cpp. |
|
I don't think it's possible in C11 either, but bindgens often essentially flatten nested types into global scope, so it works there. If the structs are unnamed, they'll essentially get something like a SHA1 hash as their name. Thinking about it again, however, I remembered that we actually stopped using bindgens for the languages where it mattered, switching to hand-crafted struct types instead. Having these fields named thus doesn't actually matter too much anymore. While I do like having them named, I feel that unnesting them kind of makes discoverability of the struct a lot worse -- you have to follow all the "links" to find the fields you're interested in, so I guess your proposed solution here is preferable. |
|
I'm glad you commented before I pushed onto this branch, the alternative would be: https://github.com/ZehMatt/zydis/tree/fix-anonymous-types-2 |
I can either open a new PR or push it onto this one, as you wish. |
|
Hmm, yeah, it's fine with me. I feel like the struct is easier to navigate when nested as-is, but if there are still bindings that depend on this, let's do it as suggested. I think it will also result in better documentation in doxygen, since it otherwise also generates hashed struct names. |
a6159b2 to
7109f84
Compare
|
Alright pushed the other branch onto this one, the CI unfortunately won't run since this is my first PR. |
|
Thanks! I started the CI. |
flobernd
left a comment
There was a problem hiding this comment.
LGTM. Just a minor style issue, but we can as well solve later.
| */ | ||
| ZydisRegister value; | ||
| } ZydisDecodedOperandReg; | ||
| /** |
There was a problem hiding this comment.
We should add some linebreaks (before all the struct comments).
There was a problem hiding this comment.
I agree, I wasn't sure if I should do it or not since I copied it out as is, I addressed that.
7109f84 to
1f1c826
Compare
Declaring named types within anonymous unions is not allowed, GCC fails to build the code otherwise.