Thus spake Timothy Wall:
I changed the last element of the structure on the Java side to be
this,
to match the definition given in the C header:
public byte[] _f =
new byte[20-2*NativeLong.SIZE-Native.getNativeSize(int.class)];
After that, it worked perfectly for me on 32-bit machines, but fails
with this exception on 64-bit machines:
Exception in thread "main" java.lang.IllegalArgumentException:
Arrays of length zero not allowed in structure
Two 8-byte longs and one 4-byte int are 20 bytes together, so that
makes
the byte array _f have zero length on a 64-bit machine. In C, that
would
just make _f point to the end of the struct.
Well, since in C you have two distinct structure definitions, you
could do the same in Java. Alternatively, you can simply ensure the
array is not zero length, since padding beyond the end of the
structure will be ignored, unless you have an array of structures. Or
you could make the final field an array as well and include the
necessary padding in that.
The simplest solution seems to be to add 1 to the length of the _f byte
array, just to ensure that _f always has nonzero length. (I've tested
that, and it works.)