struct CURLMsg {CURLMSG msg; /* what this message means */CURL *easy_handle; /* the handle it concerns */union {void *whatever; /* message-specific data */CURLcode result; /* return code for transfer */} data;};
I'll preface this by saying there are some changes I would like to make that would make recursive structs possible to declare from Julia as easy as using types.First though, the struct you point to below is not an example of a nested struct, it is a union (of size/alignment `Int`). However, that's a difference issue. For that, Jeff mentioned to me that it might be good to have something completely general for declaring offsets. I opened an issue to track discussion of syntax possibilities for this https://github.com/JuliaLang/julia/issues/2555.
For embedded structs, it may be changed in the future such that the immutable declaration embeds the struct. That is not true currently; I'm not even sure if it is completely decided now for best representation.For recursive structs (structs with pointers to other structs), I think this will take a larger change to the julia jl_value_t representation, which is possible, but could be tricky.Finally, fixed arrays also need be added for good C compatibility, as you mentioned this also needs to be addressed in some fashion.
In the meantime, you an manually pad out the structure with either a Uint8 array or a StrPack.PadByte array.
For embedded structs, it may be changed in the future such that the immutable declaration embeds the struct. That is not true currently; I'm not even sure if it is completely decided now for best representation.For recursive structs (structs with pointers to other structs), I think this will take a larger change to the julia jl_value_t representation, which is possible, but could be tricky.Finally, fixed arrays also need be added for good C compatibility, as you mentioned this also needs to be addressed in some fashion.
These were added in the package version of StrPack.jl if you need something to work with while native Julia support for these more complex structures is in progress.
Thanks, Jameson.In the meantime, you an manually pad out the structure with either a Uint8 array or a StrPack.PadByte array.Does @struct automatically handle this padding if a field is declared as a Julia Union?
For embedded structs, it may be changed in the future such that the immutable declaration embeds the struct. That is not true currently; I'm not even sure if it is completely decided now for best representation.For recursive structs (structs with pointers to other structs), I think this will take a larger change to the julia jl_value_t representation, which is possible, but could be tricky.Finally, fixed arrays also need be added for good C compatibility, as you mentioned this also needs to be addressed in some fashion.
These were added in the package version of StrPack.jl if you need something to work with while native Julia support for these more complex structures is in progress.
Cool, that's really good to hear. Does StrPack support inline aggregate declarations, or is it necessary to pre-declare as in my example? (s/union/struct/)
Does @struct automatically handle this padding if a field is declared as a Julia Union?
Since union types in Julia are not bitstypes, you can't use them in a @struct. You'll need to use an integer in place of the union and reinterpret it. However if you do that and use the appropriate padding strategy (see the StrPack.jl manual, https://strpackjl.rtfd.org/) you can avoid padding manually. The The StrPack.show_struct_layout() method can help to visualize the resulting memory layout.
I'm not sure what you mean by an "inline declaration" here. Can you give an example? (I suspect the answer is "no".)