Flexible array member initializers

Ian Pilcher arequipeno@gmail.com
Wed Jan 8 21:49:00 GMT 2014


On 01/08/2014 04:42 PM, Jonathan Wakely wrote:
>> #define SHORT_BYTES(s)  { ((s) & 0xff), (((s) >> 8) & 0xff) }
>>
>> struct foo {
>>      size_t value_size;
>>      unsigned char value[];
>> };
>>
>> static struct foo foo_short = {
>>      .value_size = sizeof(short),
>>      .value      = SHORT_BYTES(513),
>> };
>
> Where do you think those two bytes are meant to be stored?
>

Maybe I don't understand your question, but the two bytes that make up
the short get stored in the "value" element (as an array of 2 unsigned
characters).

That said, since I've realized that this simply isn't going to work for
anything but integer types, I'm going to give up on the flexible array
member for this particular use.

-- 
========================================================================
Ian Pilcher                                         arequipeno@gmail.com
"If you're going to shift my paradigm ... at least buy me dinner first."
========================================================================



More information about the Gcc-help mailing list