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: Tue, 04 Jun 2019 15:28:33 -0700 Organization: None to speak of Lines: 29 Message-ID: References: <5dd4672f-a571-40bc-bb1a-c14f6c631eb7@googlegroups.com> <87ftop38c1.fsf@bsb.me.uk> <87woi11jh1.fsf@bsb.me.uk> <86h895fdtu.fsf@mailhub.linuxsc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="2e5690e26a3a02612d58fbc15f6a6031"; logging-data="13029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Jq0qZi/CjiLitfB1ZXYRy" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:dNSIRGVHCEQMvdvVIoftubmml1w= sha1:tnjnE0NmkMMsipq0eFtYTbTchUc= Xref: csiph.com comp.lang.c:144434 David Brown writes: [...] > If using "void*" for the common pointer type will work on a given > implementation, then I am confident that using a "void (*)(void)" > pointer will work at least as well. But while it's fine to convert the > function pointers to "fvoid", converting back to appropriate callable > types should be done by casts rather than the union in order to have > fully defined behaviour. > > I believe it is fine if you use /only/ fvoid and casts, or /only/ the > union, but mixing the two is undefined (even if the risk of problems is > perhaps hypothetical). A union of function pointers can work *if* you only access the most recently stored value with its correct type. If you try to use a union for type punning of different function pointer types, the behavior is undefined (though it's likely to "work" if, for a given implementation, all function pointer types happen to have the same representation). The language guarantees that any function pointer type can be converted to any other function pointer type and back again, and yield the same value. The most obvious way to satisfy this requirement is to give all function pointer types the same representation, but the language doesn't require that. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */