Structure packing (#pragma pack/#pragma unpack) [V1.05 or later]


This specifies packing of a structure.

[Function]

-

Packing is performed for a structure that is declared at or after the location where #pragma pack was specified. The number of alignment for a structure member is set to 1.

-

Packing is not performed for a structure that is declared at or after the location where #pragma unpack was specified.

-

If the -pack option is specified simultaneously with #pragma unpack, #pragma unpack takes priority.

[Usage]

-

Declare #pragma pack/#pragma unpack before the declaration of the structure.

#pragma pack
#pragma unpack

[Example]

#pragma pack
struct s1 {
  char a;
  int b;    // The number of alignment is set to 1.
} st1;
#pragma unpack
struct s2 {
  char a;
  int b;    // The number of alignment is not set to 1.
} st2;

[Restrictions]

-

Correct operation is not guaranteed if there is a mixture of C source files with different packing specifications for the same structure.

-

Correct operation is not guaranteed if a structure, union, or address of those members whose alignment condition has been changed from two bytes to one byte by #pragma pack is passed as an argument of a standard library function.

-

Correct operation is not guaranteed if the address of a structure or union member whose alignment condition has been changed from two bytes to one byte by #pragma pack is passed to a pointer whose type has two bytes as the alignment condition and indirect reference to the pointer is performed.