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 13:57:08 -0700 Organization: None to speak of Lines: 32 Message-ID: References: <475067fe-369c-4246-84a1-05b1a3a0c6be@googlegroups.com> <5dd4672f-a571-40bc-bb1a-c14f6c631eb7@googlegroups.com> <8d90e6a8-097d-4573-a88a-1f5f56dda26d@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="a9f7c3b5d2b438cdfd64a899e3119473"; logging-data="30567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+drTvN9KomaL7s9cFUDepX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:1b955wS1Zrk37OuXrrAuhk/wGhY= sha1:k+SqCoiDcr34jGM7mcm6d6sLy9o= Xref: csiph.com comp.lang.c:144426 guinness.tony@gmail.com writes: > On Tuesday, 4 June 2019 11:24:44 UTC+1, Bart wrote: [...] >> How difficult can it be? For example: >> >> int main (void) { >> fn(1,2,3,4); >> fn("hello world"); >> } >> >> There are no declarations of 'fn' visible; should this code pass or >> fail? Apparently gcc passes this > > So it's a valid GnuC program. Irrelevant to a discussion in a C newsgroup. That depends on what you mean by "valid". In C90, the program has undefined behavior, because at most one of the two calls passes correct arguments, but no diagnostic is required. It violates a constraint in C99 and later. Recent versions of gcc with default options will warn about an implicit declaration of fn (but will not notice that the two calls are inconsistent). This is why C has prototypes. Using them avoids this problem. (I've seen arguments that non-prototype declarations can be useful in some contexts, but this is not one of those contexts.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */