Thanks for the explanation! :1 was not really googleable;)
On Monday, October 12, 2015 at 8:36:57 PM UTC-4, Steven G. Johnson wrote:
> On Monday, October 12, 2015 at 6:46:51 PM UTC-4, Matt wrote:
> Ok. It works know. I was stuck to the last two lines. I defined
> is_system_missing::Cint
> is_considered_missing::Cint.
>
>
> instead of an UInt8
>
>
> That's incorrect. In the original C code you quoted, those to fields were
> declared with a :1 suffix, i.e. as a bit field:
>
>
> http://www.tutorialspoint.com/cprogramming/c_bit_fields.htm
>
>
> That means that in the C struct, they are stored as 1 bit each, packed
> consecutively into a small number of bytes. How many bytes an how they are
> packed is implementation dependent. I'm not sure if they are packed into one
> byte (UInt8) or 4 bytes (UInt32), and as the most significant or the least
> significant bits, but they are definitely not stored as two separate Cint
> fields.
>
>
> Hence, you should declare them as a single field, and do some experimentation
> with your compiler to see what size that field should be and where the bits
> are in it. And beware that the code to access those field may not be
> portable.
>
>
>
>
> A last question: I actually have the structure itself as an argument, not a
> pointer to the structure. Is the best way to convert v.union to the right type
> unsafe_load(convert(Ptr{T}, pointer_from_objref(val)))
>
>
>
> No, pointer_from_objref is definitely not what you want here. It is only for
> working with jl_value_t* pointers via the Julia C API, which is not what you
> have here.
>
>
> You could do stick v.union into an array and reinterpret it that way, i.e.
>
>
> reinterpret(T, [v.union])[1]
>
>
> for your desired type T.