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: Wed, 29 May 2019 18:29:57 -0700 Organization: None to speak of Lines: 39 Message-ID: References: <97b08cce-ec5d-4052-9338-0026b5d449bf@googlegroups.com> <87sgt339na.fsf@bsb.me.uk> <80470a36-78de-417f-bc75-a7966c87b31e@googlegroups.com> <9cbcea67-85a8-4de3-ac01-04922ba5fc74@googlegroups.com> <7cff3be5-0432-4a90-92ed-50c74cc1eb6b@googlegroups.com> <2220fa9d-4fea-4ea6-bb32-6843143322fb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="12abe26c90a56a4d813a45bedf6a8101"; logging-data="24200"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sWuuEInXVV7q8ZvmiEQJs" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:lnoRkeUmXYKtZw0V2Qqk43c0xDE= sha1:x97LE2FGnvk+RuNyrTWDnCMccGI= Xref: csiph.com comp.lang.c:144128 James Kuyper writes: > On Wednesday, May 29, 2019 at 9:54:51 AM UTC-4, Bart wrote: [...] >> How will they interpret the missing return value here: >> >> double f(void){return;} > > In general, you'll need to check the documentation for the compiler to > find out, or you could rely upon testing, though without supporting > documentation, you can't be sure how reliable your test results will be. > > gcc with no options prints a diagnostic for such code, so this does not > count as an example of what I was talking about. However, it does > produce an executable, and testing indicates that it returns 0.0. More testing indicates that the value returned appears to be something like the result of the last expression evaluated. I changed the function to: double func(void) { double x = time(NULL); return; } and the value returned was 1559179594.000000 . This is consistent with C90, which says that the return statement is legal (because pre-ANSI code would use int functions as a stand-in for void functions), but the behavior is undefined if the caller tries to use the value. My speculation is that the value returned is whatever value happens to be in some particular CPU register. Of course gcc's warning about the `return;`, even in default mode, satisifies the requirements for C90, C99, and C11. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */