Mail Archives: djgpp/1996/09/14/14:07:38
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 -