[gclist] C++ proposal

Nick Barnes nickb@harlequin.co.uk
Wed, 29 May 1996 09:47:13 +0100


> > A special and difficult issue is how to handle a union with a pointer
> > and a non-pointer member. Consider:
> 
> 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.

Yes and no, at least for C. The difference in the effect of operators
on structs and unions in C is this: "[...] if a member of a union
object is accessed after a value is stored in a different member of
the object, the behaviour is implementation- defined." (ISO standard,
section 6.3.2.3). However, the standard also states: "A structure type
describes a sequentially allocated nonempty set of member objects
[....] A union type describes an overlapping nonempty set of member
objects [....]" (section 6.1.2.5).

I do not know about C++.

Nick Barnes