From owner-freebsd-hackers Wed Sep 4 01:57:45 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA02423 for hackers-outgoing; Wed, 4 Sep 1996 01:57:45 -0700 (PDT) Received: from freebsd.gaffaneys.com (dialup6.gaffaneys.com [134.129.252.25]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id BAA02418 for ; Wed, 4 Sep 1996 01:57:40 -0700 (PDT) Received: (from zach@localhost) by freebsd.gaffaneys.com (8.7.5/8.7.3) id CAA17602; Wed, 4 Sep 1996 02:42:29 -0500 (CDT) To: Paul DuBois Cc: kpneal@pobox.com (Kevin P. Neal), hackers@freebsd.org Subject: Re: void main References: <199609040621.BAA29078@night.primate.wisc.edu> From: Zach Heilig Date: 04 Sep 1996 02:42:28 -0500 In-Reply-To: Paul DuBois's message of Wed, 4 Sep 1996 01:21:16 -0500 (CDT) Message-ID: <877mqa680r.fsf@freebsd.gaffaneys.com> Lines: 44 X-Mailer: Gnus v5.3/Emacs 19.34 Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Paul DuBois 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 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.