Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | johnolithicsoftware@googlemail.com |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Re: Is a union a kind of class? |
| Date | 2013-12-19 11:24 -0800 |
| Organization | unknown |
| Message-ID | <24874a99-32a8-475d-88c2-36631dfb45ba@googlegroups.com> (permalink) |
| References | <52204496.5050408@bawi.org> |
On Saturday, August 31, 2013 2:20:02 AM UTC-4, Seungbeom Kim wrote: > In the taxonomy of C++ types, is a union a (kind of) class? > > > > 9[class]/5 clearly says, "A union is a class defined with the class-key > > union [...]". 5.1.2[expr.prim.lambda]/3 and 9[class]/10 also mention "a > > non-union class [type]", and 5.9[expr.rel]/2 "provided their class is > > not a union", all of which imply that a union is a class. > > > > On the other hand, 3.9.2[basic.compound]/1 lists classes and unions > > separately, which strongly implies that a union is not a class. > > > > If a union is a class, I think 3.9.2/1 is confusing (at best) and should > > be considered a defect. > > > > -- > > Seungbeom Kim > > > > > > [ comp.std.c++ is moderated. To submit articles, try posting with your ] > > [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] > > [ --- Please see the FAQ before posting. --- ] > > [ FAQ: http://www.comeaucomputing.com/csc/faq.html ] A union is like a struct except that each member variable is using the same memory spot, so unlike a struct or a class if you modify the value of one of them you modify the value of them all at once. They all share the same variable value but that value can be truncated if one of it's members is an int and the other is a char and you assign the int with the value 256 and reference it with the associated char member in a printf statement but it will still attempt to convey the memory associated with the int member. The size of a union is equal to the size of it's largest data member if I'm not mistaken. -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Previous in thread | Next in thread | Find similar
Is a union a kind of class? Seungbeom Kim <musiphil@bawi.org> - 2013-08-31 01:12 -0600
Re: Is a union a kind of class? Daniel Krügler <daniel.kruegler@googlemail.com> - 2013-08-31 23:52 -0700
Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-08-31 23:52 -0700
Re: Is a union a kind of class? johnolithicsoftware@googlemail.com - 2013-12-19 11:24 -0800
Re: Is a union a kind of class? "news" <news@fx21.iad.highwinds-media.com> - 2013-12-22 19:27 -0600
Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-12-27 13:11 -0600
Re: Is a union a kind of class? evansl <cppljevans@googlemail.com> - 2013-12-29 23:00 -0600
Re: Is a union a kind of class? James Kuyper <jameskuyper@verizon.net> - 2013-12-31 17:45 -0600
csiph-web