From owner-freebsd-hackers Wed Sep 4 04:24:56 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id EAA06866 for hackers-outgoing; Wed, 4 Sep 1996 04:24:56 -0700 (PDT) Received: from answerman.mindspring.com (answerman.mindspring.com [204.180.128.8]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id EAA06861 for ; Wed, 4 Sep 1996 04:24:54 -0700 (PDT) Received: from borg.mindspring.com (borg.mindspring.com [204.180.128.14]) by answerman.mindspring.com (8.6.12/8.6.12) with ESMTP id HAA11800; Wed, 4 Sep 1996 07:24:52 -0400 Received: from bogus.interpath.net (user-168-121-39-4.dialup.mindspring.com [168.121.39.4]) by borg.mindspring.com (8.6.12/8.6.12) with SMTP id HAA17244; Wed, 4 Sep 1996 07:24:47 -0400 Message-Id: <1.5.4.32.19960904112450.0066e000@mindspring.com> X-Sender: kpneal@mindspring.com X-Mailer: Windows Eudora Light Version 1.5.4 (32) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 04 Sep 1996 07:24:50 -0400 To: Zach Heilig From: "Kevin P. Neal" Subject: Re: void main Cc: Paul DuBois , hackers@freebsd.org Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk At 02:42 AM 9/4/96 -0500, Zach Heilig wrote: >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'. Right. Resulting in random numbers being returned to the shell. I got tired of typing m68kasm -l filename.s, and put it into a makefile. Typed 'make', and got a "Fatal Error [put random number here]" message even though there was no error. The error was "void main()". >It is also questionable to gratuitously use undefined behavior (wrt >the ISO C standard) when a 100% correct version costs nothing. Bingo. -- XCOMM Kevin P. Neal, Sophomore, Comp. Sci. \ kpneal@pobox.com XCOMM "Corrected!" -- Old Amiga tips file \ kpneal@eos.ncsu.edu XCOMM Visit the House of Retrocomputing: / Perm. Email: XCOMM http://www.pobox.com/~kpn/ / kevinneal@bix.com