-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bitstructs inside bitstructs #1977
Comments
You can use |
i think having I could just switch field type from |
It uses the field type for memory layout. If you use a uint on an LE system, then given bytes 0-3 in memory, byte 0 will have 0..7, byte 1 will have 8..15 and so on |
Thanks, that makes sense. However, my issue is not related to memory layout or capacity constraints. The correct type for this field is uint, as that is what Vulkan uses in the C API (uint32_t). To maintain binary compatibility with Vulkan, i need to use the same data types to ensure correct size, alignment, and endianness. My issue is that C3 does not allow a bitstruct (which is of type uint) to be used as a field in another bitstruct. Ideally, C3 should allow this, as bitstructs are fundamentally just integers with defined bit ranges, making them compatible with bitfields. Is there a technical reason why nested bitstructs are disallowed, or could this be considered? |
I noticed that i had left out the critical part from C header: typedef uint32_t VkFlags; i added that now. I hope it clears it up. |
probably makes sense to use anonymous bitstructs in this case, so the C3 translation is this:
Here i would like to keep using |
Converting between bitstructs and bitfields with never be a 1:1 mapping, esp since C bitfields are different on different platforms. So keep in mind that this bitlayout may match on say Linux but is not guaranteed to work on Windows. There are complexities to supporting flags in flags like you want, and even if it looks like you could make the compiler accept it, that's not the same as it actually is working. Note that unlike in C, you can perform various operations on bitstructs, and just having bitstructs in bitstructs together with |
Would it make sense for me to try to explore this a bit, ie make some test cases and see where it starts to break down, in which platform etc, and then we see if this is something the language wants to handle or not. Or you think it is probably a waste of time? |
I am not really convinced this is needed. I think we looked at a variant with a union on discord. Didn't that resolve the issues? |
Does it make sense allow
bitstruct
fields to be otherbitstruct
s, as they are basically integers as well?I'm working on Vulkan bindings where this would come handy:
Right now i get this error:
This is the related C header:
The text was updated successfully, but these errors were encountered: