Search code examples
structalignmentbytevalapack

Byte alignment in Vala


I'm having issues with Vala adding padding to struct values. Is there an equivalent to C's #pragma pack(1) or C#'s [StructLayout(LayoutKind.Sequential, Pack=1)], or possibly a workaround for this? Thanks in advance.

~ Michael K.


Solution

  • Not natively. You can define your packed structure in a separate C header file with the appropriate #pragma or __attribute__ and then create a VAPI binding for it.

    It might be possible to abuse Vala's code generation to do it (e.g., set the [CCode(cname)]], but I would advise against it.