Mail Archives: djgpp/1998/06/02/22:31:14
John M. Aldrich <fighteer AT cs DOT com> wrote:
>The problem is that most people who use don't use an integer return type
>for main seem to think that it's standard code because that's the way
>they were taught.
True, that's a good point :)
>1) The return value is used as the program's exit code, and may be used
>by any program that invokes yours.
I guess it depends; if I knew no other program would ever try to invoke
mine I might well declare main() as returning void, mostly so I didn't have
to bother writing a return at the bottom. Call me lazy :)
>Thus, the shortest legal ANSI C program is as follows:
Ah well, to be a little pedantic then we can probably shorten it further.
After all, functions that do not explicitly declare a return type are
considered to be declared as returning int anyway. Additionally, empty
parameters are permissible; IIRC, this means the function may be passed any
number and type of arguments, so it is _not_ the same as declaring void
(despite what someone else posted in another thread) since that of course
explicitly means no parameters. So our slightly shorter program is now:
main ()
{
return 0;
}
Further shortenings are possible (I suppose you could use K&R style
braces and chop off one whole line!) but I don't think it's a very
productive exercise to go any futher, heh.
Of course, you can argue that it's poor style to have a function not
explicitly declare its return type, and I would agree. Pretty much ditto
about the empty parameter list.
--
loki
loki (at) nectar.com.au http://puck.nether.net/~loki/
# Dare I disturb the universe? You bet I do!
- Raw text -