You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From what I can tell, there isn't a description of how to map unions to .NET types. This is a problem for me since I have an API that uses unions and I'd like to bind it using this library. It would also be nice if there was something like a reference sheet that described both simple and complex types in C mapped to the associated simple and complex types in .NET. According to this SO question, the StructLayout attribute combined with the FieldOffset can simulate this with structs, but I don't know how well this would map across the FFI boundary. The library I'm binding has the following structs and associated union:
The only major problem with this is that its majorly error-prone. I could use the sizeof operator but I'm not quite sure how I'd use that since FieldOffset requires a contiguous range. Is there a much better way of doing this?
The text was updated successfully, but these errors were encountered:
Using FieldOffset and an explicit struct layout is the way to go when dealing with unions, I'm afraid - this is one of those parts that gets hairy quick.
@Nihlus Is there an easier way of computing the offsets, then? I really don't want to do [FieldOffset(sizeof(a) + sizeof(b) + sizeof(c) +...)]. That just looks really ugly.
From what I can tell, there isn't a description of how to map unions to .NET types. This is a problem for me since I have an API that uses unions and I'd like to bind it using this library. It would also be nice if there was something like a reference sheet that described both simple and complex types in C mapped to the associated simple and complex types in .NET. According to this SO question, the StructLayout attribute combined with the FieldOffset can simulate this with structs, but I don't know how well this would map across the FFI boundary. The library I'm binding has the following structs and associated union:
Therefore, one possible implementation of this translation might be:
The only major problem with this is that its majorly error-prone. I could use the sizeof operator but I'm not quite sure how I'd use that since
FieldOffset
requires a contiguous range. Is there a much better way of doing this?The text was updated successfully, but these errors were encountered: