Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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: Mon, 22 Oct 2012 12:28:54 -0500 From: Steve Thompson Newsgroups: comp.lang.c Subject: Re: Compatibility question Date: Mon, 22 Oct 2012 17:23:31 +0000 Organization: Friends of the Galactic Collective Message-ID: <2nYjPo.Krd.2aRbe@gmail.com> References: <0.a87a1c8a472d870b0466.20121022022701BST.87y5izxpne.fsf@bsb.me.uk> <0.d779297035d2edccd1b4.20121022173052BST.87ehkqbhab.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: NN 6.4.3 Lines: 101 X-Trace: sv3-0f1oIkbxXqk4VWAu3CgfiH0A8/T/GqW8laGmO10oozMuQ+TBmPtc9kc6k7G/qXjYb109icGebiSFBFh!aWeByWB0HglK6LCWDvEI5eCPyOwAn4ZYXvLg+VeH7YaNz66KZ6l++YOwVw6HlQ== 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: 5729 Xref: csiph.com comp.lang.c:27520 On Mon, Oct 22, 2012 at 05:30:52PM +0100, Ben Bacarisse wrote: > Steve Thompson writes: > > > On Mon, Oct 22, 2012 at 02:27:01AM +0100, Ben Bacarisse wrote: > >> Steve Thompson writes: > >> > >> > On Mon, Oct 22, 2012 at 12:29:08PM +1300, Ian Collins wrote: > >> >> On 10/22/12 11:54, Steve Thompson wrote: > >> > >> >> >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. > >> > >> There's a terminology confusion here. Your flexible array member is > >> just that, it's not a VLA. Variable length arrays are not permitted in > >> structs and flexible array members can only appear, unsurprisingly, in a > >> struct. > > > > I suppose so. Simply stated, anytime I use "something foo[]", it will > > usually be at the end of a struct. Good enough? > > Absolutely. > > > Really, you ought to have read what I meant, rather than reading what I > > wrote. > > But I did! I think it's clear from my message that I knew exactly what > you meant; but postings might be read by silent lurkers who could be > confused if this distinction was not made very clear. Think of it as a > public service announcement. I'm sorry if it annoyed you. No annoyance taken, although now that I think of it it does show an instance of overloaded semantics, which can be confusing. When I was less experienced with C, I was confused by the fact that variables defined as structures were not pointers: struct point { int x, y, z; }; struct point a; One cannot reference 'a' (as such) in an expression even though it is a pointer in the implementation because C allows one to use structures as arguments to a function. I'd never do that in my own code, but some people may like the fact that they can pass complex data structures around as if they were simple variables. I think it wastes resources, but of course that is less of an issue today than it was when C was first developed. These days I'm thinking more and more about cache-line usage, so I am concerned with preserving the 'hotness' of my data. Copying structures around a whole lot is hostile to this paradigm, so that is one language feature I am happy to avoid. One place where it might be helpful is in the case where a single structure is used by several functions that destructively modify its contents. In that case, the original structure is preserved by passing it directly as an argument to said functions, but I don't know how useful that would be in practice. Long ago it may have been considered good practice to insulate the different layers of a program by making it impossible for a function to modify the data held by the caller, but I cannot see that as a practical benefit. Such structures are always accessible on the stack. Regards, Steve Thompson -- GOTO's are like guns. Safety is entirely contingent on the user.