Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Abstract Syntax Tree for C programs Date: Fri, 07 Jun 2019 09:54:35 -0700 Organization: None to speak of Lines: 28 Message-ID: References: <4ff90bb7-33e5-4dcd-828f-b0d40f237420@googlegroups.com> <8a72685f-2774-4187-98bf-c9ecd44b3240@googlegroups.com> <6ed2dfc1-a737-4fb3-b59a-3aa1c337061d@googlegroups.com> <9jfKE.1834916$coJ.1263461@fx36.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="0d5b010e2076a714ee1f32c348b9a975"; logging-data="12759"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18KhY9fX6f9r1ISA1a4d9Ej" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:PnR3LkMWwjMzcn1yxl1khgvucEY= sha1:MLOYxUpxlbZeDw9WskpvTfn/KMo= Xref: csiph.com comp.lang.c:144602 Bart writes: [...] > Sometimes it's more convenient to do without the unions (which can run > foul of various C constraints about the order in which members can be > read and written). > > A simple example is of an array which can represent byte-code (or it > could work for other kinds of processing), where the first element is > pointer to a function that handles a particular operation, followed by 0 > or more object pointers that are consumed by the function, and that > point to any operands or arguments. > > And then those are followed by the next function pointer, etc. The > simplest representation is a void* array. Wouldn't an array of int be even simpler? What's that you say? You can't portably store a function pointer value in an int object? Do tell. An array of unions isn't quite as simple, but it has the considerable virtue of being valid and portable C. As a bonus, it works around the gcc bug we've discussed in this thread. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */