Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: [Solved] Need some help getting to my feet Date: Fri, 04 May 2018 09:19:46 -0700 Organization: None to speak of Lines: 50 Message-ID: References: <0db1659a-6249-47d0-8fab-baf080d32f76@googlegroups.com> <3vWGC.147526$pC1.7144@fx07.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="067bb2bcf7afe0ff6fbb1a4a3dfb8c90"; logging-data="24168"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wd8IZAgA6lnr/7aN8G1N/" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:6anebsiqe+KhHLPPFcbDild+mmY= sha1:HNGLlytU+PF0t13YvZ766UYhxGU= Xref: csiph.com comp.lang.c:130187 bartc writes: > On 04/05/2018 09:36, Wouter Verhelst wrote: >> On 28-04-18 01:25, bartc wrote: >>>>> At most one of these will have the correct arguments, so at least one >>>>> call must be wrong, but the compiler will say nothing unless you >>>>> explicitly tell it to report an error. >>>> >>>> So don't do that. >>> >>> So if someone wants to avoid inadvertently writing dangerous >>> constructions in a program, all they have to do Not To Write Them. >> >> By "that", I assume Keith meant "don't write foo() when you mean foo(void)". Yes. >> Once you do that, my gcc starts complaining about your f("one", "two", >> "three"); as a call with too many arguments. > > Yes, but ... suppose someone writes foo() by mistake. How is that > going to be detected? It likely won't be detected by the compiler. gcc doesn't complain by default, or with a reasonable set of command-line options. There might be an option that will cause it to warn about it. (clang, with reasonable options, warns about an incorrect call but not about the declaration.) Old-style non-prototype function declarations are still part of the language, though they're marked as obsolescent. There is rarely, if ever, a good reason to use them. At least some compilers won't help you detect uses of them. Yes, this is unfortunate. I wish they had been removed from the language in C99 or C11, and I wish gcc could be coaxed to warn about them. (There have been discussions about reasons to keep them in the language; I would prefer not to go over that again here.) Nevertheless, avoiding old-style function declarations is not that difficult, and they can be detected by reviewing your code. This is me, again, agreeing with one of your complaints about C. As usual, I expect you will refuse to acknowledge this and probably blame me personally for something I am describing, not defending. -- 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"