On Montag, 18. Februar 2019 12:22:27 CET Christian Schoenebeck wrote: > On Sonntag, 17. Februar 2019 21:37:26 CET Peng Yu wrote: > > Because I want to use the previously allocated memory, I don't want to > > call "rs_init(&yylval->str)" in any action. So YYSTYPE must be a > > struct instead of a union. Is it a good practice to use struct instead > > of union? > > Yes, it is. The only advantage by using a union as a type is that you save > some tiny amount of memory, but a union is also less safe and harder to > debug. So personally I would barely ever use union as fundamental type with > Bison.
Btw, you can also mix both approaches, e.g.: struct _YYSTYPE { union { int inum; float fnum; }; rapidstring str; Foo_t foo; }; typedef it appropriately, I usually use C++ code, but you get the idea. Best regards, Christian Schoenebeck _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison