Mail Archives: djgpp/1996/12/20/19:39:20
Erik Max Francis wrote:
>
> Actually, the mere declaration
>
> main() { ... }
>
> in fact does define main as returning int and taking no parameters. In C,
> the default return type of a function when not explicitly specified is int.
> Also, when no parameters are explicitly specified, in a definition it is
> taken as of taking no parameters. (In a prototype, in C, it doesn't say
> anything about the parameter list; in C++, it always means no parameters.)
And the version of gcc in DJGPP v2.01 complains about functions that
default to int if you compile with -Wall. To me, this indicates
potentially unsafe programming techniques which should be avoided.
In general, any time the compiler produces a warning about something,
you should attempt to get rid of that warning, or you are getting into
programming habits which may come back to bite you some day.
Likewise, an empty parameter list in C is a throwback to K&R C where you
could declare a function to take an unspecified number of parameters.
This is _so_ unsafe that the ANSI folks are considering removing it in
the next version of the C spec, or so I heard.
Just to add a bit to this thread, I deliberately set out to examine what
occurs if you declare void main() and do not specify an exit value when
your program terminates. The results were not surprising: the return
value was essentially random. It changed depending on what command line
options I passed to the program and what the program calculated as a
result. While this may not be the case with all compilers, it should
come across as an absolute and indisputable message: DO NOT USE void
main()!
l8r
--
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com |
| Proud owner of what might one | http://www.cs.com/fighteer |
| day be a spectacular MUD... | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------
- Raw text -