Ahh nevermind, I think I see — declaring the "stuff" field to be the 
largest of the possible types and then reinterpreting the result as the 
correct type seems to work. Thanks!

On Saturday, May 3, 2014 12:21:18 PM UTC-5, James Porter wrote:
>
> How would I convert manually? Right now I'm trying to use a placeholder 
> bitstype of the appropriate size and reinterpret it is the correct 
> immutable type, but I'm getting BoundsErrors in reinterpret and I'm not 
> sure if this is the right thing to be doing.
>
> On Saturday, May 3, 2014 12:14:03 PM UTC-5, Isaiah wrote:
>>
>> The size of a union is the size of the largest element. There is no way 
>> to access one memory range as different names/types like a C union, but you 
>> could do the down-conversion from the max type manually as needed.
>>
>> Also you might want to have a look at the StrPack package (not sure if it 
>> supports unions).
>>
>>
>> On Sat, May 3, 2014 at 2:25 AM, James Porter <porter...@gmail.com> wrote:
>>
>>> Hi all—
>>>
>>> I am fooling around with wrapping a C library which declares a struct in 
>>> a similar manner to:
>>>
>>>
>>> typedef struct Thing {
>>>     //other non-union fields here . . .
>>>     union {
>>>         A a;
>>>         B b;
>>>         C c;
>>>     } stuff;
>>> }
>>>
>>>
>>>
>>> Where A, B, and C are all other structs defined in this package. How do 
>>> I deal with the stuff field here? I've been looking around at library 
>>> examples and posts on the mailing list about how to handle wrapping this 
>>> sort of thing and I can't find anything. LIBSVM.jl provides a good 
>>> example<https://github.com/simonster/LIBSVM.jl/blob/master/src/LIBSVM.jl#L19-L47>of
>>>  wrapping a relatively complex structure that doesn't involve unions, 
>>> there are posts on the mailing 
>>> list<https://groups.google.com/forum/#!searchin/julia-dev/union$20struct/julia-dev/p6DUUSdtY2A/h3J3V7T3OcoJ>
>>>  about 
>>> wrapping unions of pointers, ints, etc., but I can't find anything about 
>>> wrapping unions of structs. Does anyone have any advice for how to handle 
>>> this sort of thing?
>>>
>>> Cheers,
>>> James
>>>
>>
>>

Reply via email to