public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: Ian Pilcher <arequipeno@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Flexible array member initializers
Date: Wed, 08 Jan 2014 22:21:00 -0000	[thread overview]
Message-ID: <CAH6eHdRq9-TiWBS+R6=TQL7D4c7s+cHaAqEw4e_oP5T2PkZGjA@mail.gmail.com> (raw)
In-Reply-To: <52CDC7C8.5070804@gmail.com>

On 8 January 2014 21:48, Ian Pilcher wrote:
> 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).

The point of my question is that the 'value' member is an incomplete
type, it does not have any storage, so there is nowhere to store those
two bytes.

But I didn't realise GCC has a non-standard extension that does allow
what you're doing, automatically allocating space after the struct:
http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

  reply	other threads:[~2014-01-08 22:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08  5:13 Ian Pilcher
2014-01-08  8:59 ` Jonathan Wakely
2014-01-08 20:41   ` Ian Pilcher
2014-01-08 21:00     ` Marc Glisse
2014-01-08 21:46       ` Ian Pilcher
2014-01-08 21:43     ` Jonathan Wakely
2014-01-08 21:49       ` Ian Pilcher
2014-01-08 22:21         ` Jonathan Wakely [this message]
2014-01-08 23:23     ` Ángel González
2014-01-11  2:03       ` Ian Pilcher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH6eHdRq9-TiWBS+R6=TQL7D4c7s+cHaAqEw4e_oP5T2PkZGjA@mail.gmail.com' \
    --to=jwakely.gcc@gmail.com \
    --cc=arequipeno@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).