Path: csiph.com!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Type system protocols rest atop fundamental data Date: Thu, 15 Jun 2017 09:27:18 -0700 Organization: None to speak of Lines: 59 Message-ID: References: <31b443b2-2142-417f-812a-955280ff39d8@googlegroups.com> <1d495f2d-77f2-4a89-b695-ae74df6ea664@googlegroups.com> <87fuf28f8o.fsf@bsb.me.uk> <9Ij0B.155016$m76.119451@fx35.am4> <2Ck0B.72727$O06.58650@fx43.am4> <1Ps0B.155401$m76.34278@fx35.am4> <4pv0B.20170$Oz1.7806@fx34.am4> <87shj170sn.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="3b2fcea57d669583082fb2a69ed6ae26"; logging-data="4197"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/DRhpOA28FXn/glSv4BxUF" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:lBMiI8PuhR3BHQOh3wEmNIJgkn0= sha1:47/WfzlbdJwjkVZz4FsEP2o32Pw= Xref: csiph.com comp.lang.c:112272 Ben Bacarisse writes: > bartc writes: > >> Give me an example of a freely available C compiler (other than DMC >> which is the only line that notices the mismatched arguments), which >> out of the box and with default options, diagnoses: >> >> randommadeupfunction(1,2,3,"blah"); >> randommadeupfunction(1e37); >> >> as an error. > > You need to say a bit more for that even to be an error. In C90 and up > a declaration can make those lines correct (though not necessarily very > useful) and in K&R C they are OK without one. Only in C90 code with no > declaration in scope is this definitely an error. Given this complete translation unit: int main(void) { randommadeupfunction(1,2,3,"blah"); randommadeupfunction(1e37); } In C90, it violates no constraint or syntax rule, and no diagnostic is required, but the behavior is undefined. Both calls implicitly create the same declaration in the enclosing block: int randommadeupfunction(); which is consistent with both calls, but there is no possible *definition* of the function that would give both calls defined behavior. (Yes, this is an ugly and error-prone language feature, which is why it's no longer in the language.) You can even add a prototype that makes the entire translation unit valid, and without undefined behavior if the function is defined appropriately elsewhere: int main(void) { void randommadeupfunction(double, ...); randommadeupfunction(1,2,3,"blah"); randommadeupfunction(1e37); } On the first call, the initial argument is implicitly converted from int to double. A more apt example might have passed a string literal as the first argument in the first call, and a floating constant in the second; then no variadic prototype could make both calls valid. [...] -- 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"