Hi,
I'm using the c2000 21.6.0.LTS compiler and I tried both COFF and EABI format, the result was the same.
typedef struct {
unsigned a;
unsigned b;
} entry_t;
typedef struct {
unsigned len;
entry_t entries[];
} array_t;
const array_t array = {
.len = 3,
.entries = {
{ .a = 1,},
{ .a = 2},
{ .a = 3},
},
};
const unsigned neighbor = 0xabcd;
/**
* main.c
*/
volatile unsigned va;
volatile unsigned vb;
int main(void)
{
va = array.entries[2].a;
vb = array.entries[2].b;
return 0;
}
I would expect vb == 0, but after running the code it's actually vb == 0xABCD, the value of neighbor. It looks like the compiler calculates the space for array wrong. Adding a dummy entry at the end of the array would fix the problem.
Best regards,
Simon