Quick question I couldn't find an answer to in the docs:

My understanding is that if I have a C struct like:

struct MyStruct {
    const void* ptr1;
    int int1;
    const void* ptr2;
    int int2;
};

Then I can declare a Julia type like:

immutable type MyType
    ptr1::Ptr{Void}
    int1::Cint
    ptr2::Ptr{Void}
    int2::Cint
end

And I can then load the contents of a MyStruct* returned by a ccall into an 
initialized Julia MyType using unsafe_load (or an array of them with 
pointer_to_array).

But what if the C struct is declared with a packing that isn't the default 
for all of the struct members on that platform, like:

#pragma pack(push, 4)
struct MyStruct {
    const void* ptr1;
    int int1;
    const void* ptr2;
    int int2;
};
#pragma pack(pop)

Now, the above should no longer work on x86_64, right, because Julia will 
expect the second void* to have an 8-byte alignment as is default on 
x86_64, so will look for it 16 bytes into the struct, rather than 12.

Is there a recommended way of dealing with this issue? Should I be using 
the StrPack module?

Thanks,
Will

Reply via email to