In a library I'm working with I found a structure like this:
typedef struct {
uint16_t id;
uint16_t len;
union {
uint8_t data[0];
uint16_t data16[0];
uint32_t data32[0];
}
} packet_t;
So this is a packet with flexible-lengthed data, with an access to each of the word lengths.
But the standard says an object cannot have zero size, so compiling this raises a warning ("ISO C forbids zero-size array").
I compile the code in gcc so this zero-sized array hack will just do fine thanks to its extension. But is there any way I can be really "pedantic" about this? Flexible Array Member didn't help because of the union.
It will be simple if I just throw away the multibyte data members, but I want to keep them as much as possible because some functions in the library rely on these.
At first I thought I could use one-sized arrays instead, but I'm not sure if there is no side affects at all. Any recommendations?