Date: 04 Sep 1996 02:42:28 -0500 From: Zach Heilig <zach@blizzard.gaffaneys.com> To: Paul DuBois <dubois@primate.wisc.edu> Cc: kpneal@pobox.com (Kevin P. Neal), hackers@freebsd.org Subject: Re: void main Message-ID: <877mqa680r.fsf@freebsd.gaffaneys.com> In-Reply-To: Paul DuBois's message of Wed, 4 Sep 1996 01:21:16 -0500 (CDT) References: <199609040621.BAA29078@night.primate.wisc.edu>
index | next in thread | previous in thread | raw e-mail
Paul DuBois <dubois@primate.wisc.edu> writes:
> Um, so what exactly is wrong with void main, other than that you don't
> happen to like it?
Strictly speaking, there are exactly two correct versions of main():
int main(void);
and
int main(int argc, char *argv[]);
Note that "char *argv[]" is exactly equivalent to "char **argv", and
if you leave off the return type, it defaults to int, so these
declarations may look a little different in practice.
You wouldn't write code like:
/* bad.c */
#include <stdio.h>
char *sin(double);
main() { printf("sin(1) == %s\n", sin(1)); }
/* end bad.c */
compile with:
$ cc bad.c -lm
and expect it to work properly. 'int' and 'void' are not compatible
types, just like 'char *' and 'double' are not compatible types.
If you wonder where the other declaration of main() expecting a return
type of 'int' is, remember that something has to call your program
(/usr/lib/crt0.o), and it thinks that main() returns an 'int'.
It is also questionable to gratuitously use undefined behavior (wrt
the ISO C standard) when a 100% correct version costs nothing.
--
Zach Heilig (zach@blizzard.gaffaneys.com) | ALL unsolicited commercial email
Support bacteria -- it's the | is unwelcome. I avoid dealing
only culture some people have! | with companies that email ads.
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?877mqa680r.fsf>
