| |||||
Technical Support Support Resources
Product Information | C166: PACK DIRECTIVEInformation in this article applies to:
QUESTIONWhat does the PACK directive do? Does it let me pack structure elements on byte or word boundaries? ANSWERYes. That's exactly what the PACK directive does. The PACK directive causes the C166 Compiler to generate byte-aligned structures with word elements. This is useful when exchanging data structures with other systems where no alignment is required. NOTE: The C166 compiler generates considerably more code to access byte-aligned words. For this reason, PACK(1) should be used only when necessary. PACK(1) assumes that structure pointers point to word-aligned structures. If your application uses structure pointers to byte-aligned structures, you must use the BYTEALIGN directive in addition to PACK(1). For example:
#pragma pack(1) /* byte alignment */
struct s1 {
int i1; // i1 has offset 0
char c1; // c1 has offset 2
int i2; // i2 has offset 3
char c2; // c2 has offset 5
int i3; // i3 has offset 6
char z1; // z1 has offset 8
};
#pragma pack() /* reset to default alignment */
struct s2 {
int i1; // i1 has offset 0
char c1; // c1 has offset 2
int i2; // i2 has offset 4
char c2; // c2 has offset 6
int i3; // i3 has offset 8
char z1; // z1 has offset 10
};
SEE ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Thursday, September 07, 2000 | ||||
| |||||