Is void main(void) ANSI standard??
Dave P. Schaumann
dave at cs.arizona.edu
Tue Mar 12 11:35:41 AEST 1991
In article <1991Mar11.085439.1 at sysjj.mdcbbs.com> hooverm at sysjj.mdcbbs.com (SQUID 6 on the DARK side) writes:
>When a program is compiled/linked and there is no value returned to main,
>certain platforms will return a warning message stating that this function
>doesn't return a value.
>
>I thought that by declaring: void main(void) that I would get around this.
>
>Is this ANSI standard? If it is valid, why doesn't my SUN SparcStation like
>it? [...]
Well, first you have to understant that one of the oddities of C (IMHO) is
that if you declare a function like this:
main() { ... }
The return type becomes "int" by implication. This is probably not the best
idea in the world, but the backward-compatability crowd wouldn't have it
any other way.
Declaring main as a void is *not* a good idea. Many systems take the value
returned by main() to be the "exit status" of the program. (Usually, a
value of 0 means all is well, and a non-0 value means some kind of error
has occurred). If you don't really care about this, just put a return 0 ;
(or exit(0)), and all should be well.
Of course, you should see another thread appearing in this group for a
discussion about return values under VMS.
--
Dave Schaumann | dave at cs.arizona.edu | Short .sig's rule!
More information about the Comp.lang.c
mailing list