Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 04 Sep 1996 07:24:50 -0400
From:      "Kevin P. Neal" <kpneal@pobox.com>
To:        Zach Heilig <zach@blizzard.gaffaneys.com>
Cc:        Paul DuBois <dubois@primate.wisc.edu>, hackers@freebsd.org
Subject:   Re: void main
Message-ID:  <1.5.4.32.19960904112450.0066e000@mindspring.com>

next in thread | raw e-mail | index | archive | help
At 02:42 AM 9/4/96 -0500, Zach Heilig wrote:
>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'.

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1.5.4.32.19960904112450.0066e000>