Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 20 Oct 2012 07:13:08 -0500 From: Steve Thompson Newsgroups: comp.lang.c Subject: Re: Compatibility question Date: Sat, 20 Oct 2012 04:01:22 +0000 Organization: Friends of the Galactic Collective Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: NN 6.4.3 Lines: 44 X-Trace: sv3-EsKqbfLxWZHcPzeReQJvZkijB2geUSZGVsdKt3SCL13K3JN48sH41FpAZ+m3J3X+8pdyq6Gh5j+GRkw!7sSVm5CsfuLSyvSs4XV/NZQ9Nr7xROpVm9lvnZHrSnueRbhorhKqUdvLeGklOg== X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2559 Xref: csiph.com comp.lang.c:27410 On Sat, Oct 20, 2012 at 04:20:53PM +1300, Ian Collins wrote: > On 10/20/12 16:08, Steve Thompson wrote: > >I have been using structures containing zero-length arrays as a means > >of combining descriptors and array data in a single allocation unit. > >Something like the following is a common idiom: > > > >struct foo { > > int a, b; > > size_t len; > > char p[0]; > >}; > > That should really be > > char p[]; > > Which is the standardised (as of C99) form of the struct hack. > > >So far, so good. My questions regards the availability of zero-length > >arrays in common systems. That is, if I wish my code to be compatible > >with most C compilers in use today, should I worry about avoiding > >zero-length arrays, or is the feature old enough, with sufficient > >prevalence to make it's use reasonable in portable code? > > Most compilers should support the standard form, or the zero length > array form of the struct hack. I was mainly wondering what the cutoff date was for this feature. If C compilers deployed within the last ten years or so support the p[0] idiom, I won't feel as if I'm excluding platforms that might otherwise be expected to run my code. The workaround is not a huge problem since the accesses will be insulated from the user by my functions, but it is less trouble to write if I don't have to cast everything. Regards, Steve Thompson -- GOTO's are like guns. Safety is entirely contingent on the user.