Array doubles in size if a struct defines both its uint16_t words and uint8_t bytes
问题 I have an array each of whose elements could be either uint16_t or a pair of uint8_t. Its elements are defined as a union of a uint16_t and a sub-array of 2 uint8_t. Unfortunately, the compiler (MicroChip XC16) allocates twice as much memory as it should for the array. typedef union { uint16_t u16; // As uint16_t uint8_t u8[2]; // As uint8_t } my_array_t; my_array_t my_array[1]; // 1 word array, for testing my_array[0].u8[0] = 1; my_array[0].u8[1] = 2; uint8_t byte_0 = my_array[0].u8[0]; //