This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: module level flags
- From: Russ Allbery <rra at stanford dot edu>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 29 Sep 2002 14:03:20 -0700
- Subject: Re: module level flags
- Organization: The Eyrie
- References: <20020929203840.16208F2D6A@nile.gnat.com>
Robert Dewar <dewar@gnat.com> writes:
> By the way it certainly seems that YACC is incorrect here in its
> approach, and at the very least should discuss the implications of its
> choice for YYSTYPE.
A simple define of YYSTYPE to a single C type is only appropriate for very
simple parsers where all tokens return the same type data. Any more
complex parser should use the %union directive, which declares YYSTYPE as
a union type. This is stated in the bison manual, although not in
precisely that way (instead, the bison manual shows using %union
everywhere and only mentions in one side page that for very simple parsers
you can define YYSTYPE instad).
By using a simple YYSTYPE when YYSTYPE is actually storing multiple
different data types, you're lying to the compiler, and it's unsurprising
that things break. It's not portable, may not work at all on platforms
where pointers can not be stored safely in integral types, requires
unnecessary casts, and destroys what type checking the C compiler is able
to do, even apart from the aliasing concerns.
--
Russ Allbery (rra@stanford.edu) <http://www.eyrie.org/~eagle/>