On Wed, 23 Mar 2005, Hans Aberg wrote:
At 14:16 +0100 2005/03/23, Laurence Finston wrote:
>Add it where?
Just add a field, invisible to the user, with the type information.
I meant "in C++ or in Bison?"
> Dynamic allocations must have such a field with the size, so that it
can be properly deallocated.
Yes, this information must be stored somewhere. However, when
programming applications in C++, one usually doesn't have to worry about
the sizes of objects. Even when using C, I usually just use `sizeof()'.
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;
};
Yes, but this isn't a `union' anymore.
> >I suspect that doing so in C++ would break compatibility
>to C.
Not really, as C and C++ are different languages.
The compatibility of C++ to C is not complete but reasonably close.
I think this is one of the best and most important features of C++.
If C++ was less compatible to C, it's quite possible that I wouldn't be
able to use it in my parser rules.