Groups | Search | Server Info | Login | Register


Groups > comp.lang.c > #398384

Re: function declaration without args no longer works

From cross@spitfire.i.gajendra.net (Dan Cross)
Newsgroups comp.lang.c
Subject Re: function declaration without args no longer works
Date 2026-05-05 18:09 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <10tdbor$5uj$2@reader1.panix.com> (permalink)
References <10sl5na$5ov$1@reader1.panix.com> <86zf2ewcm8.fsf@linuxsc.com> <10tcc5j$e45$1@reader1.panix.com> <10tcd0u$a3j4$1@kst.eternal-september.org>

Show all headers | View raw


In article <10tcd0u$a3j4$1@kst.eternal-september.org>,
Keith Thompson  <Keith.S.Thompson+u@gmail.com> wrote:
>John Forkosh <forkosh@panix.com> writes:
>> Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>>> John Forkosh <forkosh@panix.com> writes:
>>>> John Forkosh <forkosh@panix.com> wrote:
>>>>> Michael B?uerle <michael.baeuerle@gmx.net> wrote:
>>>>>> Have you tried "-std=c99" (or whatever standard
>>>>>> your code was written for)?
>>>>>
>>>>> Thanks, Michael.  I've tried it now:) Indeed, as soon
>>>>> as I saw your "-std=" I vaguely recalled that switch.
>>>>> And, yeah, both -std=c99 and (as also suggested)
>>>>> -std=gnu17 ignore the problem, and compile just fine
>>>>> Thanks again.
>>>>
>>>> Update:  While subsequently trying to compile some even older
>>>> code, written circa 1991, I had to go back even further,
>>>> to -std=c89 (or equivalently -ansi as per the man cc page).
>>>> And then, no errors, no warnings, not even with -pedantic.
>>> 
>>> What were the sorts of things that caused diagnostics when
>>> compiled under -std=c99?
>>
>> Three errors (identical with or without -pedantic)...
>>
>> bash-5.3$ cc -DTESTDRIVE -DNOTMSDOS -std=c99 -pedantic -lm treelib.c -o treelib
>> treelib.c: In function 'talloc':
>> treelib.c:205:11: error: implicit declaration of function 'tallchk' [-Wimplicit-function-declaration]
>>   205 |     if ( !tallchk() ) tree=(double *)NULL; /* set error if corrupt */
>>       |           ^~~~~~~
>> treelib.c: At top level:
>> treelib.c:1986:1: error: return type defaults to 'int' [-Wimplicit-int]
>>  1986 | main ( argc, argv )
>>       | ^~~~
>> treelib.c: In function 'main':
>> treelib.c:2149:29: error: implicit declaration of function 'close'; did you mean 'fclose'? [-Wimplicit-function-declaration]
>>  2149 |   if ( fp != (FILE *)NULL ) close(fp);  /* close output file */
>>       |                             ^~~~~
>>       |                             fclose
>>
>> ... at line  205, I indeed used tallchk() without declaring it
>> within the talloc() function where it's used.
>>     at line 1986, I indeed wrote main() instead of int main().
>>     at line 2149, I indeed meant fclose().
>> A little sloppier of me than I usually am (or maybe than I like
>> to think I usually am). But code has a good deal of slop and
>> #ifdef stuff because it had to simultaneously compile and run
>> on PCs under msdos, DECstation 5000 and Apollo 10000 under Unix,
>> and VAX 11/780 under VMS. And it was even expected to give
>> identical results.
>>
>> That last one might have caused problems, but never did.
>> treelib.c only compiles main() when compiled with cc -DTESTDRIVE,
>> and then output goes to stdout unless you explicitly tell it
>> a filename when running it, i.e.,  ./treelib  #periods  [outputfile]
>> I typically tested onscreen, but, hmmm, when testing it now
>> with a filename, it nevertheless works fine, without throwing
>> any errors at eoj when it calls close(). And the code
>> doesn't #include <unistd.h> and it does call close() with
>> a FILE *fp rather than an int fd.
>
>If the code were going to be maintained, I suggest that upgrading it
>to C99 would make it more stable (modulo the instability if making
>any changes at all to existing code).
>
>Missing return types and implicit declarations are easy enough to
>fix, and the code is still compatible with C90.
>
>The close() error is interesting.
>
>close(), a POSIX function, takes an int argument, a small integer
>value that's a file descriptor.  If you declare it incorrectly
>(or not at all) and call it with a FILE* argument, it's likely the
>pointer value will be interpreted as a very large integer which
>will not be a valid file descriptor.  I just tried it, and close()
>returned -1 and set errno to EBADF.  If you don't check the return
>value, most likely the close() call will do nothing and the file
>will be closed when the program terminates.  Other than output not
>being flushed immediately, it might not cause any real problems.

It's a resource leak.  Likely harmless in this case, since this
code is (apparently?) in a test harness and this is the only
file pointer in question, but more generally file descriptors
are a scarce resource compared to, say, RAM, and a bug like this
could have real consequences if too many are open at one time.

>But it's still an error worth fixing (again, assuming that the
>program is still worth maintaining; otherwise let it rest in peace).

Amen.

	- Dan C.

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 13:59 +0000
  Re: function declaration without args no longer works Michael Bäuerle <michael.baeuerle@gmx.net> - 2026-04-26 16:24 +0200
    Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 16:29 +0000
      Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-04 19:36 +0000
        Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-05-05 00:15 -0700
          Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-05 09:10 +0000
            Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-05-05 11:17 +0200
              Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-05 11:07 +0000
            Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-05-05 02:24 -0700
              Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-05 11:20 +0000
              Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-05 18:09 +0000
                Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-07 12:52 +0000
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-07 14:51 +0000
              Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-06 11:41 +0200
            Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-05-05 10:03 -0700
              Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-05-07 12:35 +0000
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-05-08 07:36 -0700
                Re: function declaration without args no longer works antispam@fricas.org (Waldek Hebisch) - 2026-05-08 18:39 +0000
  Re: function declaration without args no longer works richard@cogsci.ed.ac.uk (Richard Tobin) - 2026-04-26 14:32 +0000
    Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 16:35 +0000
    Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-29 16:43 -0700
      Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-30 08:39 +0200
  Re: function declaration without args no longer works Michael S <already5chosen@yahoo.com> - 2026-04-26 17:50 +0300
    Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 16:39 +0000
      Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-27 00:30 +0000
        Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-27 08:30 +0200
          Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-28 07:02 +0000
            Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 10:16 +0200
              Re: function declaration without args no longer works antispam@fricas.org (Waldek Hebisch) - 2026-04-28 15:33 +0000
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 20:24 +0200
                Re: function declaration without args no longer works antispam@fricas.org (Waldek Hebisch) - 2026-04-28 20:22 +0000
              Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-29 06:22 +0000
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-29 09:15 +0200
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-29 10:06 +0200
                Re: function declaration without args no longer works Michael S <already5chosen@yahoo.com> - 2026-04-29 11:25 +0300
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-29 11:26 +0200
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-29 20:07 -0400
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 00:14 +0000
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-29 17:57 -0700
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-30 03:09 +0200
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 00:48 -0700
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-30 20:18 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-01 04:12 +0000
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-30 23:29 -0700
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-05-01 19:31 +0200
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-05-01 13:49 -0400
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-01 12:49 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-01 22:31 +0000
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-02 00:13 +0000
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-01 19:27 -0700
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-05-01 19:28 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-02 03:07 +0000
                Re: function declaration without args no longer works scott@slp53.sl.home (Scott Lurndal) - 2026-05-02 16:16 +0000
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 01:39 +0000
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 00:38 -0700
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-30 03:07 -0700
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 05:54 -0700
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-30 14:32 -0700
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-30 09:45 -0400
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 12:48 -0700
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-04-29 11:05 +0100
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-29 16:32 -0700
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-30 01:22 -0700
                Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-29 10:42 +0000
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-29 14:31 -0700
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-30 08:42 +0200
                Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-30 13:17 +0000
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-30 14:40 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 22:14 +0000
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-29 18:55 +0000
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-29 21:19 +0000
                Re: function declaration without args no longer works Tim Rentsch <tr.17687@z991.linuxsc.com> - 2026-04-29 16:46 -0700
            Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 14:25 +0200
              Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-28 13:13 +0000
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 15:48 +0200
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-04-28 15:05 +0100
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 16:37 +0200
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-28 14:02 -0700
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-29 09:29 +0200
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-29 02:49 -0700
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-29 20:06 -0400
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-29 17:13 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 00:45 +0000
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-04-29 21:11 -0400
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 01:40 +0000
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-29 20:09 -0700
                Re: function declaration without args no longer works scott@slp53.sl.home (Scott Lurndal) - 2026-04-30 14:57 +0000
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-30 15:07 +0000
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-04-30 16:20 +0100
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-30 16:10 +0000
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-04-30 17:48 +0100
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-30 22:31 +0200
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-30 22:18 +0000
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-05-01 00:25 +0100
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-01 00:08 +0000
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-05-01 01:24 +0100
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-30 17:46 -0700
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-01 01:55 +0000
                Re: function declaration without args no longer works Bart <bc@freeuk.com> - 2026-05-01 10:48 +0100
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-05-01 11:20 +0000
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-30 20:23 -0700
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-05-01 10:32 +0200
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-30 14:43 -0700
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-30 22:34 +0000
                Re: function declaration without args no longer works James Kuyper <jameskuyper@alumni.caltech.edu> - 2026-05-01 13:32 -0400
                Re: function declaration without args no longer works scott@slp53.sl.home (Scott Lurndal) - 2026-05-01 18:12 +0000
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-30 03:50 +0200
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-30 08:52 +0200
                Re: function declaration without args no longer works "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2026-04-28 14:56 -0700
                Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-28 15:41 -0700
                Re: function declaration without args no longer works Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-04-29 21:20 +0000
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 17:14 +0200
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 17:31 +0200
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-28 19:06 +0000
                Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-28 21:44 +0200
                Re: function declaration without args no longer works Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2026-04-28 17:06 +0200
                Re: function declaration without args no longer works cross@spitfire.i.gajendra.net (Dan Cross) - 2026-04-28 19:23 +0000
  Re: function declaration without args no longer works David Brown <david.brown@hesbynett.no> - 2026-04-26 17:35 +0200
    Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 16:50 +0000
    Re: function declaration without args no longer works Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2026-04-26 15:52 -0700
  Re: function declaration without args no longer works Andrey Tarasevich <noone@noone.net> - 2026-04-26 08:38 -0700
    Re: function declaration without args no longer works John Forkosh <forkosh@panix.com> - 2026-04-26 16:56 +0000

csiph-web