Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Set the result of void function Date: Fri, 29 Sep 2017 09:15:04 -0700 Organization: None to speak of Lines: 58 Message-ID: References: <877ewm1ook.fsf@bsb.me.uk> <65ac971c-10a1-41b1-876d-cdded04ea432@googlegroups.com> <6308c8a5-6a1e-4667-bac4-1cdaf18e7e55@googlegroups.com> <5b6b3759-5c3e-4b65-9c54-a96ccc0dd393@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="61a8d29e3e3ce5c1ce3f75578cd619a7"; logging-data="21313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+k6oy89wrl24FRZTXvDjro" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:dxG8EPZ6crQ7J971CX2p8kD0g80= sha1:EHUrM/lSmpLi8r/yD/kvKgiAA3w= Xref: csiph.com comp.lang.c:120550 David Kleinecke writes: > On Thursday, September 28, 2017 at 6:45:18 PM UTC-7, Keith Thompson wrote: >> David Kleinecke writes: [...] >> > As nearly as I can tell it would be possible to use >> > non-prototyped functions where we now use variadic >> > functions. I think that is a bad idea. But ... >> >> The behavior would be undefined. >> >> Given: >> >> printf("%d\n", 42); >> printf("%s\n", "hello"); >> >> there is no way to declare and define printf such that both calls will >> have defined behavior other than by using the ", ..." syntax. >> >> Any call to a variadic function has undefined behavior unless a correct >> prototype for that function is visible. > > I don't want to defend the undefensible. But the context > would be > int printf () { ...} > which is not the library printf. So it has nothing to do with the actual printf, which has to accept a variable number of arguments. Using a different name to avoid confusion: int not_printf() { /* ... */ } empty parentheses in a function *definition* mean that the function has no parameters. The difference between that and int not_printf(void) { /* ... */ } is that the latter imposes a constraint on callers, so that calling it with one or more arguments must be diagnosed. > With no prototype this > should work - provided the implementation gets the right > arguments in the right place. > > As I said before I don't like this idea. But it seems > legal. No, calling not_printf() with one or more arguments has undefined behavior but need not be diagnosed. This is why we use prototypes. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"