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 10:56:06 -0700 Organization: None to speak of Lines: 42 Message-ID: References: <8a72685f-2774-4187-98bf-c9ecd44b3240@googlegroups.com> <6ed2dfc1-a737-4fb3-b59a-3aa1c337061d@googlegroups.com> <9jfKE.1834916$coJ.1263461@fx36.am4> <87k1dxs5y0.fsf@bsb.me.uk> 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="U2FsdGVkX19rPhiV4atLpJeSAsjzigG3" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:A7ISoUqsMuOQnkx2PFo8hSpiwXM= sha1:4yQB/RXh3rs4GkSTnOuAvvf7gv0= Xref: csiph.com comp.lang.c:144610 Bart writes: > On 07/06/2019 17:42, Ben Bacarisse wrote: [...] >> Not function pointers. > > Why not? They seem to work: > > C:\c>type c.c > #include > > typedef struct {int d,m,y[100];} date; > > int main(void) { > date d; > printf("%p %p %p %p %p %p\n",d,d,d, main,main,main); > } > > C:\c>gcc -std=c11 -pedantic-errors c.c That code has undefined behavior, but it doesn't violate a constraint or syntax error, so the language doesn't require a diagnostic. Recent versions of gcc (4.8 and later, of the versions available to me) do produce warnings. Did your gcc print any warnings? Incidentally, on my system the last three printed values are not the same. This is an unsurprising result of undefined behavior. [...] > But how would your officially print the value of a function pointer? There is no portable way to print a function pointer value. Casting to void* and using "%p" is likely to "work", but the cast itself is problematic at best. Or you could access a function pointer object as as array of unsigned char and print its representation. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */