help-bison
[Top][All Lists]
Advanced

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

Re: Union Type Object problem


From: Hans Aberg
Subject: Re: Union Type Object problem
Date: Fri, 6 Aug 2004 20:42:07 +0200

At 00:25 +0200 2004/08/06, Laurence Finston wrote:
>Sorry, I was careless.  Actually, I don't know whether unions can contain
>_pointers_ to objects with constructors, although your error message seems to
>indicate they cannot.

The definition POD is (from the C++ standard, ISO/IEC 14882:1998):

4) The acronym POD stands for "plain old data."

[basic.types] 3.9:10 Arithmetic types (3.9.1), enumeration types, pointer
types, and pointer to member types (3.9.2), and cv-qualified versions of
these types (3.9.3) are collectively called scalar types. Scalar types,
POD-struct types,
POD-union types (clause 9), arrays of such types and cv-qualified versions
of these types (3.9.3) are collec-tively called POD types.

So pointer types are POD's and OK in unions.

>   You could just use `void*' and cast the pointers to
>`Expression*' in the rules.  That's what I do.

I think that one might loose polymorphy that way, or only preserve it in a
non-C++ standard way (it might not run on some C++ compilers).

I am happy with my polymorphic object setup, despite that I cannot use
unions, and therefore loose memory when I write:

class semantic_type {
public:
  long number_;
  std::string text_;
  mli::object object_;

  semantic_type() : number_(0) {}
};

#define YYSTYPE semantic_type


Instead of the implementation produced by %union:

union semantic_type {
  long number_;
  std::string text_;
  mli::object object_;
};

#define YYSTYPE semantic_type

If you produce a very large stack, and memory is critical then you should
not use my setup. But I also use the text_ and number_ fields, at times, in
parallel with the object_ fields, which usually carries the main
information. For example, when certain lookup table information should be
communicated to the parser.

  Hans Aberg






reply via email to

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