Problem with interfacing C code to D

Andrej Mitrovic andrej.mitrovich at gmail.com
Mon Jan 9 17:07:53 PST 2012


Jesus christ, sorry about that my keyboard script went crazy and posted that.

What I was going to say is it's likely a mismatch of the struct sizes.
In the second example you are dereferencing the pointer on the D size,
which does a field-by-field copy of the pointed-to struct. But D will
only read the exact amount of bytes that is defined by the structure.
So if you end up reading e.g 176 bytes, but the C structure is
actually more than that, then the C-side (X11) will end up reading
into D memory past the 176th byte, and will segfault.

If you can, try seeing if you can get the size of the Display
structure in C code (e.g. use printf("%d", sizeof(Display))), and then
compare that to D with writeln(Display.sizeof). They must have the
same size.


More information about the Digitalmars-d-learn mailing list