Article View: comp.std.c++
Article #3268Re: class.union questions
From: Fergus Henderson
Date: Tue, 06 Feb 1996 18:27
Date: Tue, 06 Feb 1996 18:27
35 lines
2289 bytes
2289 bytes
kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763) writes: >dirk@becker.adviser.com (Dirk Becker) writes: > >|> In Section 9.6.1 Unions [class.union] there is a large collection of >|> restrictions on the union itself and on candidate member classes. >|> I would like to ask for reasons of several of them: > >One of the principle goals was that a union be compatible with a C >union, at least in use. One of the rules is that the addresses of all >of the elements in the union compare equal to the address of the union >itself, when cast to the appropriate type. > >|> a) "A union shall not have base classes. A union shall not be used as >|> a base class." > >Without this rule, you either break the address rule, or you impose >some special class layout on unions. Nevertheless, contrary to what you seem to be implying, that rule is not necessary for C compatibility. C++ structs can be very different to C structs, but C compatibility is preserved for a certain category of C++ structs, namely POD-structs. In the case of unions, the same thing could have been done - rule (a) could have been dropped, yet C compatibility could still have been be supported for POD-unions. -- Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3 --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID:
<4f7l8h$t0e@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<v01530500ad38ee830c96@[194.163.74.11]> <KANZE.96Feb5132431@slsvewt.lts.sel.alcatel.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: class.union questions Date: 06 Feb 1996 10:27:03 PST Organization: Comp Sci, University of Melbourne Approved: austern@isolde.mti.sgi.com Message-ID: <4f7l8h$t0e@mulga.cs.mu.OZ.AU> References: <v01530500ad38ee830c96@[194.163.74.11]> <KANZE.96Feb5132431@slsvewt.lts.sel.alcatel.de> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 6 Feb 1996 13:32:01 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMRedlEy4NqrwXLNJAQEyCgH/TchVO/723+i5IVua3O0ZQZ+yIVD8uvmF WlbnZCUaNpuguTBuodNuBwiU/0yL6CJsZRSV8C3hOk5U4z3cPyvbnw== =lcpr Originator: austern@isolde.mti.sgi.com