www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/14/14:07:38

Xref: news2.mv.net comp.os.msdos.djgpp:8613
Newsgroups: comp.os.msdos.djgpp
From: design AT netcom DOT com (Chris Waters)
Subject: old C vs. standard (was Re: Binary files and ^C chars-try again)
Message-ID: <designDxpwK1.K2G@netcom.com>
Organization: Design and Delivery
References: <Pine DOT GSO DOT 3 DOT 94 DOT 960911160113 DOT 2084A-100000 AT zippy> <3238BAD4 DOT A45980C AT alcyone DOT com>
Date: Sat, 14 Sep 1996 10:16:49 GMT
Lines: 56
Sender: design AT netcom19 DOT netcom DOT com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <3238BAD4 DOT A45980C AT alcyone DOT com>,
Erik Max Francis  <max AT alcyone DOT com> wrote:
>Samuel Vincent wrote:

>> This is very old C..  I would recommend using ANSI C as follows:

>> int main(int argc, char *argv[]) {

>Presently, traditional-style function declarations are still supported in ANSI

After a fashion--you may have unexpected conversions of char or short to
int and float to double, however.  And they are deprecated.  And the
standard is currently in review--this might disappear as soon as next
year (though I grant it's unlikely).

>> >     FILE *fp,*fopen();

>> The fopen function is declared in stdio.h I believe.  1) You don't need to
>> declare it further here.

>Right.

Technically (as long as we're being language lawyers), it is, in fact,
illegal to declare it here.  In fact, this may simply fail on Borland C
for OS/2, where some standard library functions are declared with a
"pascal" interface.  Yes, Borland *is* allowed to do that by the standard.

>> 2) You seem to have declared it incorrectly
>> as taking no arguments...

>In C++, yes; in C, no.

Correct, but again, you may have unexpected difficulties with unintended
promotions, as with old-style declarations.  (I hate the term
"traditional" in this context, as it sounds more legitimate than "old".)

>> That exit() should really just be:   return 0;

>There's nothing wrong with using exit to terminate a program, even if you're
>in main.

But an integer function should return an integer.  Therefore, you would
have to use:

#include <stdlib.h>  /* or do I mean stddef.h? */
int main()
{
    /* blah blah blah... */
    exit (0);
    return 0;
}

Which is redundant and silly.  :)

Note also that exit(), technically, requires one of the standard headers
to be included; return does not.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019