xc16

Array doubles in size if a struct defines both its uint16_t words and uint8_t bytes

為{幸葍}努か 提交于 2020-03-21 17:52:42
问题 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]; //

Array doubles in size if a struct defines both its uint16_t words and uint8_t bytes

半腔热情 提交于 2020-03-21 17:51:38
问题 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]; //

Array doubles in size if a struct defines both its uint16_t words and uint8_t bytes

淺唱寂寞╮ 提交于 2020-03-21 17:51:03
问题 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]; //

GCC error “<variable> causes a section type conflict”

牧云@^-^@ 提交于 2019-12-23 08:50:34
问题 Why is there a compiler error when attempting to place two (RAM) variables, which only differ by their initialisation values, into the same section? Problem The C source: int __attribute__((section(".in_my_data"))) _foo = 1; int __attribute__((section(".in_my_data"))) _bar = 0; The (relevant) GCC compiler output: mcve/main.c:75:45: error: _bar causes a section type conflict The linker script contains the following line in the SECTIONS definition, but the (fatal) error is from the compiler,