This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: module level flags


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/>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]