Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Abstract Syntax Tree for C programs Date: Tue, 04 Jun 2019 10:08:15 -0700 Organization: A noiseless patient Spider Lines: 41 Message-ID: <86lfyhffcw.fsf@mailhub.linuxsc.com> References: <475067fe-369c-4246-84a1-05b1a3a0c6be@googlegroups.com> <5dd4672f-a571-40bc-bb1a-c14f6c631eb7@googlegroups.com> <87ftop38c1.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="822064cc3cc2a6ececc8a34836f7fa7b"; logging-data="11032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BCiF3Yv0FF6Zb96qWmafB49U/KYpt0+Q=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:73jaYg9xjhvhPusXpHyRybw2rfI= sha1:j1ffnFica3K17AMsj1XRQzsTuUg= Xref: csiph.com comp.lang.c:144414 Ben Bacarisse writes: > Bart writes: > >> On 04/06/2019 07:56, Ike Naar wrote: >> >>> On 2019-06-03, Bart wrote: >>> >>>> Using a void* to store a void(*)(void) is not a big deal, you >>>> don't want -pedantic-errors to stop your build because of it. >>> >>> Using a function pointer (and not an object pointer) to store a >>> function pointer isn't a big deal either. >> >> How would you create the following table: >> >> void fn1(void){} >> void fn2(int a){} >> void fn3(int a,double b){} >> int fn4(void){return 0;} >> char* fn5(double a){return "";} >> >> void* table[] = {fn1,fn2,fn3,fn4,fn5}; >> >> Suggestions to use void(*)(void) for the table element aren't as >> good. > > As good as what? > >> (Because you could actually write table[3]() without the compiler >> picking that up. > > You simply can't do that in C. If that is a deal-breaker, you > need a different language. > > BTW, table[3]() would be a valid call, even in a version of C > where every function pointer objects carried its own type around. Do you mean to say it's okay to call fn4() through a void (*)(void) function pointer, even though the return type of fn4() is int? Or was that just an oversight? Or did I completely misunderstand you?