Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #27480

Re: Compatibility question

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 Sun, 21 Oct 2012 18:55:50 -0500
From Steve Thompson <stevet810@gmail.com>
Newsgroups comp.lang.c
Subject Re: Compatibility question
Date Sun, 21 Oct 2012 23:50:51 +0000
Organization Friends of the Galactic Collective
Message-ID <OYMHVs.wix.4bcJD@gmail.com> (permalink)
References <Li3Gtk.7Rk.IPeax@gmail.com> <aeejkmFnpi3U11@mid.individual.net> <bTPtYj.bf9.VEBUJ@gmail.com> <aegfofFnpi3U14@mid.individual.net> <SodxpQ.GJL.0E2fB@gmail.com> <aejeq5FqjpsU11@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
User-Agent NN 6.4.3
Lines 93
X-Trace sv3-RG1YcVOX/hXQq/Lvdbbof1T6PcW0D1TAAmF7VQne1e5/xHNjON5JmBVkHBKOCOrSysWOW1cq7tjJ6eZ!1dMbW4pdNI4CNaHmDtW9/+RFIsj2Qpn1DsIoDGcMsmDrTAAE0EWavUoqC7qn2w==
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 5096
Xref csiph.com comp.lang.c:27480

Show key headers only | View raw


On Mon, Oct 22, 2012 at 12:29:08PM +1300, Ian Collins wrote:
> On 10/22/12 11:54, Steve Thompson wrote:
> >On Sun, Oct 21, 2012 at 09:26:54AM +1300, Ian Collins wrote:
> >>On 10/20/12 17:01, Steve Thompson wrote:
> >>>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.
> >>
> >>As Ben pointed out, the pre-C99 form was a single element array.  I
> >>think the zero element array is a gcc extension.  So if you really want
> >>to support every possible compiler, use p[1] and document what you are
> >>doing.  Otherwise use the standard form.
> >
> >Working on another part of the software I'm writing, I learned today
> >that I must use TLS.  There is no point trying to get around that
> >constraint, so the list of potential targets is going to shrink quite
> >a lot.
> 
> Times Literary Supplement?

Thread Local Storage; variables declared with the __thread qualifier
so they are specific to a thread instance.  My zero-overhead allocator
requires a thread-specific descriptor, so I'm committed.
 
> >Now that I've noticed that the GCC documentation has been updated (I
> >may not have read that section for ten years, now that I think of it),
> >it does indeed say that the C99 standard includes support for flexible
> >arrays, with similar semantics to the old gcc zero subscript hack, so
> >I will use that.
> 
> You can't use a VLA as a structure member (how would you declare it?).

>From the GCC info pages:

  In ISO C99, you would use a "flexible array member", which is slightly
different in syntax and semantics:

   * Flexible array members are written as `contents[]' without the `0'.

   * Flexible array members have incomplete type, and so the `sizeof'
     operator may not be applied.  As a quirk of the original
     implementation of zero-length arrays, `sizeof' evaluates to zero.

   * Flexible array members may only appear as the last member of a
     `struct' that is otherwise non-empty.

   * A structure containing a flexible array member, or a union
     containing such a structure (possibly recursively), may not be a
     member of a structure or an element of an array.  (However, these
     uses are permitted by GCC as extensions.)

So I'm free and clear.  My VLAs will be in structures which are not
encapsulated in other structures.



Regards,

Steve Thompson

-- 
GOTO's are like guns.  Safety is entirely contingent on the user.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 03:08 +0000
  Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-20 16:20 +1300
    Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-20 11:50 +0100
      Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-20 11:41 -0700
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:04 +0000
          Re: Compatibility question Barry Schwarz <schwarzb@dqel.com> - 2012-10-21 20:27 -0700
    Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-20 04:01 +0000
      Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-21 09:26 +1300
        Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 22:54 +0000
          Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-22 12:29 +1300
            Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-21 23:50 +0000
              Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 02:27 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 02:28 +0000
                Re: Compatibility question Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-10-22 11:18 -0400
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 16:19 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:37 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:40 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 17:30 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 17:23 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 10:52 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 18:42 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-22 21:06 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 22:52 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 03:33 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:28 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 16:45 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 17:53 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:41 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 21:28 +0100
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-23 20:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 12:26 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 20:39 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 15:53 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 00:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-23 20:06 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 11:18 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 12:04 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-24 23:10 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:58 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-25 01:46 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 19:40 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-24 20:20 +0000
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 14:38 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-24 17:55 -0400
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:29 -0700
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-24 15:21 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-26 03:30 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:02 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-27 00:04 +0000
                Re: Compatibility question Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-27 20:15 +0100
                Re: Compatibility question Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2012-10-27 16:36 -0600
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:36 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 22:42 +0300
                Re: Compatibility question Greg Martin <greg@softsprocket.com> - 2012-10-27 14:30 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-27 22:57 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 17:14 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-27 18:04 -0700
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-24 16:46 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-25 01:18 +0000
                Re: Compatibility question Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2012-10-27 21:08 +0300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-28 17:38 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:38 +0100
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 16:50 -0700
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-23 12:33 +0000
                Re: Compatibility question Öö Tiib <ootiib@hot.ee> - 2012-10-22 14:23 -0700
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 17:26 -0400
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 10:55 +1300
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:27 +0000
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-22 22:44 +0100
                Re: Compatibility question Les Cargill <lcargill99@comcast.com> - 2012-10-22 17:15 -0500
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:13 +0100
                Re: Compatibility question James Kuyper <jameskuyper@verizon.net> - 2012-10-22 18:35 -0400
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 00:14 +0100
                Re: Compatibility question Steve Thompson <stevet810@gmail.com> - 2012-10-22 23:42 +0000
                Re: Compatibility question Ian Collins <ian-news@hotmail.com> - 2012-10-23 13:35 +1300
                Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-22 17:01 -0700
                Re: Compatibility question "BartC" <bc@freeuk.com> - 2012-10-23 01:47 +0100
              Re: Compatibility question Keith Thompson <kst-u@mib.org> - 2012-10-21 19:27 -0700

csiph-web