This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

#pragma pack(n) scope

Does #pragma pack(n) apply to all the structures in a source code or it has to be applied to each structure separately ?
It's not clear from the manual.
In one place it says:
"You can use #pragma pack(n) to make sure that any structures with unaligned data are packed."
In other:
"This pragma aligns members of a structure to the minimum of n"

Parents
  • the assumption that structures on both ends will have the same data alignment

    That assumption should alsways be assumed to be wrong.

    In a nutshell, C data structures are for internal use of the C program. They are generally unsuitable to define any external interface data, and any attempts to abuse them causes problems you just don't need.

    There's a reason no self-respecting data interchange format is defined in terms of C structs: it simply wouldn't work. Those things are defined in terms of bits, octets and similarly universal items for a reason.

Reply
  • the assumption that structures on both ends will have the same data alignment

    That assumption should alsways be assumed to be wrong.

    In a nutshell, C data structures are for internal use of the C program. They are generally unsuitable to define any external interface data, and any attempts to abuse them causes problems you just don't need.

    There's a reason no self-respecting data interchange format is defined in terms of C structs: it simply wouldn't work. Those things are defined in terms of bits, octets and similarly universal items for a reason.

Children
No data