Maybe the title is confusing, but the idea is simple. Given the following structure:
struct z {
uint64_t _a;
uint64_t _b;
struct {
char _c[64];
uint64_t _d;
} data[0];
} __attribute__((packed));
How might one get the size of the type of the anonymous inner struct data
? I do not want to name the struct and clutter the namespace, but I do need its size when computing the total length of what a serialized buffer would look like with a non-zero data
trailer.
If you try this you'll find something similar to:
struct z *p;
sizeof(struct z) == 16
sizeof(*p) == 16
sizeof(p->data) == 0
These results are expected. However, what I was hoping to see was the following:
sizeof(typeof(p->data)) == 72
But, unfortunately, I still get
sizeof(typeof(p->data)) == 0
I thought it might be because the struct was unnamed, but after providing it with a name you'll find the earlier results are still true.
Is there a way to get the size of an anonymous inner zero-length structure?