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: Fri, 19 Oct 2012 22:13:49 -0500 From: Steve Thompson Newsgroups: comp.lang.c Subject: Compatibility question Date: Sat, 20 Oct 2012 03:08:30 +0000 Organization: Friends of the Galactic Collective Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: NN 6.4.3 Lines: 46 X-Trace: sv3-fjrPxDREGSH7PqPzFRMmzgPMChuxsO3/GGSuOvPP1GmmA7QHzRVkQ4a6eRPg9Q9yYNOdtAbTr0Ipxbi!kbpeylE9JN6bZnXvLmaBiv+ir4JD+muvtR3aUOatwFt4Pfm6Wh1NWkjWMvvRiA== 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: 2095 Xref: csiph.com comp.lang.c:27400 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]; }; struct foo *q; For the noobs, q->p[x] is obviously convenient, however before gcc supported zero-length arrays, the arrangement would be something like this: struct foo { int a, b; size_t len; }; struct foo *q; char *x; In this instance, assuming that the array of char is intended to be available immediately following struct foo, the access is done as follows: *((char *)(q + 1)) = ' '; 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? Regards, Steve Thompson -- GOTO's are like guns. Safety is entirely contingent on the user.