Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Steve Thompson <stevet810@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Compatibility question |
| Date | 2012-10-22 17:23 +0000 |
| Organization | Friends of the Galactic Collective |
| Message-ID | <2nYjPo.Krd.2aRbe@gmail.com> (permalink) |
| References | (5 earlier) <aejeq5FqjpsU11@mid.individual.net> <OYMHVs.wix.4bcJD@gmail.com> <0.a87a1c8a472d870b0466.20121022022701BST.87y5izxpne.fsf@bsb.me.uk> <JLOhFS.Dvd.FY9Iy@gmail.com> <0.d779297035d2edccd1b4.20121022173052BST.87ehkqbhab.fsf@bsb.me.uk> |
On Mon, Oct 22, 2012 at 05:30:52PM +0100, Ben Bacarisse wrote:
> Steve Thompson <stevet810@gmail.com> writes:
>
> > On Mon, Oct 22, 2012 at 02:27:01AM +0100, Ben Bacarisse wrote:
> >> Steve Thompson <stevet810@gmail.com> writes:
> >>
> >> > On Mon, Oct 22, 2012 at 12:29:08PM +1300, Ian Collins wrote:
> >> >> On 10/22/12 11:54, Steve Thompson wrote:
> >> <snip>
> >> >> >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.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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