I have some old C code that makes somewhat heavy use of packed structures. I'm looking into using Go as a wrapper for this code, but am having difficulty finding a way to pass or even write definitions for these structures.
Example:
import "unsafe";
type AlignTest struct {
c byte;
y int16;
z int16;
q int32;
}
func main() {
vr := new(AlignTest);
fmt.Println(unsafe.Sizeof(*vr), "\n");
}
Returns 12 rather than the 1+2+2+4 = 9 that I would want with a packed/unaligned struct.
I know that I could just create a byte array and do the parsing manually, but that seems very brittle and error prone...