In C, an array normally isn't allowed to have size 0 (unless I use the one or other compiler-side extension).
OTOH, there are VLAs whose length might turn out to be 0.
Are they allowed?
I am talking about the following code:
void send_stuff()
{
char data[4 * !!flag1 + 2 * !!flag2];
uint8_t cursor = 0;
if (flag1) {
// fill 4 bytes of data into &data[cursor]
cursor += 4;
}
if (flag2) {
// fill 2 bytes of data into &data[cursor]
cursor += 2;
}
}
The result is a data
array with a length of 0, 2, 4 or 6, depending on the combination of the flags.
The question is now: Is this valid code for the case the array turns out to have length 0?