Please note: We are aware of an issue affecting replies on the Arm Community forums, which may not be loading as expected.
We apologize for any inconvenience and appreciate your patience while we investigate and work to resolve the issue.
Thank you for your understanding.
Hi,
with the following sample code...
typedef __packed struct { uint8_t field_1; uint8_t field_2; uint8_t field_3; uint8_t field_4; } T_Sub; typedef __packed struct { T_Sub Sub; uint8_t field_1; uint8_t field_2; uint8_t field_3; uint8_t field_4; } T_Data; typedef __packed union { T_Data content; uint8_t buffer[sizeof(T_Data)]; } T_Union; const T_Union C_Union = { {1,2,3,4}, 1, 2, 3, 4, 5}; // The following (no union, just strcut) has the same problem /* typedef __packed struct { T_Data content; } T_Struct; const T_Struct C_Struct = { {1,2,3,4}, 1, 2, 3, 4, 5}; */
I get:
error: #146: too many initializer values
I'm using uVision4. The same code works on other compilers. I'm obviously missing something big but I can't figure what...
Yes, it works... kinda fussy :-) It isn't fussy at all. Strip down what you are doing:
typedef __packed struct { uint8_t field_1; uint8_t field_2; uint8_t field_3; uint8_t field_4; } T_Sub; const T_Sub T_Sub_example = {1, 2, 3, 4}; typedef __packed struct { T_Sub Sub; uint8_t field_1; uint8_t field_2; uint8_t field_3; uint8_t field_4; } T_Data; const T_Data T_Data_example = { /* T_Sub_example */ {1, 2, 3, 4}, /* field_1 to field_4 */ 5, 6, 7, 8 }; typedef __packed union { T_Data content; uint8_t buffer[sizeof(T_Data)]; } T_Union; const T_Union T_Union_example = { /* T_Data_example */ { /* T_Sub_example */ {1, 2, 3, 4}, /* field_1 to field_4 */ 5, 6, 7, 8 } /* empty since the array "buffer" is not initialized */ };