| |||||
Technical Support Support Resources
Product Information | CARM: ALIGNMENT FOR CHAR AND SHORTInformation in this article applies to:
QUESTIONI have an array of byte (unsigned char) values. Since my source code uses some tricks to access this array, I want to force the char variable to a 32-bit (int) boundary. Is there a way to change the alignment with a C pragma directive? ANSWERThe CARM User's Guide contains a section that discusses how to align variables to various boundaries. While it is possible to change the default alignment for int or short to a byte-alignment, it is not possible to force char variables to a 32-bit alignment. However, you may define the char array in a union that contains an int variable as shown below:
union u {
unsigned char c[10]; // the char array
unsigned int i; // force 32-bit int alignment
};
union u array;
:
array.c[i] = 0; // access to int-align char array
:
MORE INFORMATION
Last Reviewed: Friday, July 15, 2005 | ||||
| |||||