I want to declare a structure with a flexible array element in it, and then use sizeof() on it. Prototype:
typedef struct { uint16_t length; uint8_t array[][2]; } FLEXIBLE_t;
Then I declare this:
const FLEXIBLE_t test = { .length = sizeof(test), .array = { { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 }, { 8, 9 } } };
Everything compiles in order (GCC), but when I look at test.length , it has a value of 2, i.e. it only considers uint16_t for length .
How can I calculate the size of the structure at compile time? It seems that the compiler is using a prototype, not a specific instance.
c arrays struct sizeof flexible-array-member
user1522973
source share