Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Struct and Union |
| Date | 2015-07-11 13:04 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87bnfivr24.fsf@bsb.me.uk> (permalink) |
| References | <a653fc98-5fae-48ff-ba1c-d7b53adee150@googlegroups.com> <87io9rwxgh.fsf@bsb.me.uk> <d6025b96-21fa-4b77-a363-4c446eafd1d3@googlegroups.com> <877fq7ws1q.fsf@bsb.me.uk> <65287b12-3597-4503-93e8-3059efa82a87@googlegroups.com> |
"Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: > On Friday, July 10, 2015 at 6:45:34 PM UTC-4, Ben Bacarisse wrote: >> "Rick C. Hodgin" <rick.c.hodgin@gmail.com> writes: >> <snip example of making a "discriminated union" in C> >> >> > That being the case, the OP should use C++ then and make it a class >> > with encapsulated accessors. >> >> The OP should *consider* using C++, but saying that they should use C++ >> is too strong. > > I think the OP should use the method I suggested, a union structure, > with the identifer member. :-) That *and* C++! You sure know how to tell people what they should do, don't you? :-) > But if he's going to use your suggestion, then it makes much more > sense to use a class and the encapsulation it affords. If the OP did that they would not be using my suggestion. My suggestion was about what to do in C. >> This is one of those places where, from the C programmer's point of >> view, you have to keep reinventing the wheel. This problem was solved >> decades ago (see, for example, Algol 68) and solved again and again in >> various ways every few years or so since. But all of these solutions >> are just a shade above the level that C is pitched at in terms of >> programming abstractions. > > I would not call it reinventing the wheel. Certain abilities in > code are fundamental, and we will all arrive at them when considering > how best to handle a situation. The OP has come up with two > solutions, and there are several others which would serve this cause. > In my view, none of them are re-inventing the wheel, they're just > assessing which one is best in this case for this app. None of the C suggestions really solve the problem. A solution would help the programmer write error-free code, and the proffered options only help a little towards that goal. So, yes, re-inventing the wheel is the wrong phrase -- it's more like re-inventing part of a wheel-like thing that is almost round. > I still choose my suggestion. :-) Though, if C had the simple class, > I would go with that one. ... and if C had a discriminated union I'd go with that, and if it had type-classes (not the same as object classes) I'd go with those. There are lots of things the OP can't use in C -- no need to limit your suggestions to just one thing they can't use in C. -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Struct and Union janus <emekamicro@gmail.com> - 2015-07-10 00:49 -0700
Re: Struct and Union Richard Heathfield <rjh@cpax.org.uk> - 2015-07-10 09:04 +0100
Re: Struct and Union janus <emekamicro@gmail.com> - 2015-07-10 01:40 -0700
Re: Struct and Union Richard Heathfield <rjh@cpax.org.uk> - 2015-07-10 09:50 +0100
Re: Struct and Union Richard Heathfield <rjh@cpax.org.uk> - 2015-07-10 13:44 +0100
Re: Struct and Union "Bill Davy" <Bill@SynectixLtd.com> - 2015-07-10 12:37 +0100
Re: Struct and Union Keith Thompson <kst-u@mib.org> - 2015-07-10 08:24 -0700
Re: Struct and Union Keith Thompson <kst-u@mib.org> - 2015-07-12 12:53 -0700
Re: Struct and Union Ian Collins <ian-news@hotmail.com> - 2015-07-10 21:32 +1200
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-10 05:12 -0700
Re: Struct and Union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-10 17:35 +0100
Re: Struct and Union David Kleinecke <dkleinecke@gmail.com> - 2015-07-10 10:18 -0700
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-10 10:23 -0700
Re: Struct and Union James Kuyper <jameskuyper@verizon.net> - 2015-07-10 13:47 -0400
Re: Struct and Union Keith Thompson <kst-u@mib.org> - 2015-07-10 12:38 -0700
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-10 10:27 -0700
Re: Struct and Union Bartc <bc@freeuk.com> - 2015-07-10 13:55 +0100
Re: Struct and Union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-10 21:48 +0100
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-10 13:51 -0700
Re: Struct and Union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-10 23:45 +0100
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-10 17:43 -0700
Re: Struct and Union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 13:04 +0100
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-11 05:15 -0700
Re: Struct and Union Bartc <bc@freeuk.com> - 2015-07-11 14:01 +0100
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-11 06:05 -0700
Re: Struct and Union "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-11 06:13 -0700
Re: Struct and Union Keith Thompson <kst-u@mib.org> - 2015-07-11 13:51 -0700
Re: Struct and Union Martin Shobe <martin.shobe@yahoo.com> - 2015-07-11 16:51 -0500
Re: Struct and Union Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-11 23:13 +0100
Re: Struct and Union Keith Thompson <kst-u@mib.org> - 2015-07-11 17:39 -0700
Re: Struct and Union Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-07-11 16:56 -0700
Re: Struct and Union Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-07-10 18:52 -0700
Re: Struct and Union Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-10 19:12 -0700
csiph-web