help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %union errors that shouldn't be there


From: Laurence Finston
Subject: Re: %union errors that shouldn't be there
Date: Wed, 23 Mar 2005 14:16:09 +0100 (MET)

Hans Aberg wrote:

> With unions, the problem is, if con-/de-structors are non-trivial, that it
> is impossible to know which ones to apply and when.

Stroustrup, _The C++ Programming Language_, Special Edition, 2000,
p. 257, Section 10.4.12:

"Consequently, a union may not have members with constructors or
destructors.  It wouldn't be possible to protect that object against
corruption or to guarantee that the right destructor is called when
the union goes out of scope."

> The union does not
> contain any type information which field is selected. If one adds that,
> unions with non-trivial con-/de-Structors would be possible.

Add it where?  I suspect that doing so in C++ would break compatibility
to C.  I haven't checked whether any C++ implementation has
implemented such a facility as an extension, though.

It might be possible to implement a way of using class types with
constructors and destructors in a `%union' in Bison, but not with an
unextended C or C++ union.  This is just my opinion, but I think it's
simpler to just use `void*'.

Laurence




reply via email to

[Prev in Thread] Current Thread [Next in Thread]