> The union does notcontain any type information which field is selected. If one adds that, unions with non-trivial con-/de-Structors would be possible.
Add it where?
Just add a field, invisible to the user, with the type information. Dynamic allocations must have such a field with the size, so that it can be properly deallocated. So it nothing strange as such. In fact, one can do thi by hand:
class Union { public: typedef Type int;
union Value { ... };
Type type; Value Value; };
Then write the class Union as to hide away the constructor stuff. Perhaps Bison should support such a version. Then one does not need to use the %destructor stuff. The drawback is the extra memory each int takes on the parser stack.
I suspect that doing so in C++ would break compatibility to C.
Not really, as C and C++ are different languages. One would need to be aware that the C++ unions
I haven't checked whether any C++ implementation has implemented such a facility as an extension, though.
Doubt it. The C++ paradigm is to use a class hierarchy instead.
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*'.
So you have a suggestion of an extended union above. -- Hans Aberg
_______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison