[gclist] C++ proposal

D. Hugh Redelmeier hugh@mimosa.com
Wed, 29 May 1996 14:49:57 -0400


| From: cef@geode.geodesic.com (Charles Fiterman)
| To: gclist@iecc.com
| Subject: Re: [gclist] C++ proposal
| 
| From: Fergus Henderson <fjh@cs.mu.OZ.AU>

[this attribution was missing from Charles' message]

| > Stefan Monnier, you wrote:
| > > 
| > > > A special and difficult issue is how to handle a union with a pointer
| > > > and a non-pointer member.
| 
| > > I always thought that the 'definition' of "union" makes it semantically
| > > equal to "struct". It's only the intended meaning which differs. In other
| > > words, "union" is only a hint to the compiler that only one of the entries
| > > inside the union will be used at a time.
| > 
| > You thought wrong.  There are a number of important semantic
| > differences, including the requirement that all members of a union have
| > the same address (or rather that the address of a union member, suitably
| > converted, points to the union -- and vice versa.)
 ...

| The common address requirment is nowhere in the definition of C or C++.

The way I interpret Fergus' statement, he is in fact correct.

In my copy of the ANSI standard, in section 3.5.2.1 (with the pre-ISO
section numbers):

	A pointer to a union object, suitably converted, points to each of
	its members (or if a member is a bit-field, then to the unit in
	which it resides), and vice versa.

"Suitably converted" is surely intended to mean "cast"; it does not
mean adding some arbitrary offset.

Hugh Redelmeier
hugh@mimosa.com  voice: +1 416 482-8253