How can exit(n) give a function the return value?

  • Thread starter lovecreatesbeauty
  • Start date
K

Keith Thompson

Jordan Abel said:
Some of the people in this group have radical ideas about the semantics
of main() in particular. I think Peter Nilsson's claim (which I disagree
with) is that even without an exit statement, main doesn't need to
return a value, since main's caller is outside the scope of the C
standard.

It depends on what you mean by "doesn't need to". In C90, falling off
the end of main returns an arbitrary status to the environment. (I
don't have my C90 standard handy so I don't remember whether it's
unspecified, undefined, or something else.) This doesn't affect the
execution of the program itself, just what happens after the program
finishes.

In C99, though, falling off the end of main is equivalent to "return
0;" (a bad rule IMHO, but there it is), so it's no longer even
possible for main not to return a value. (You could return the value
of an uninitialized variable, but that invokes undefined behavior as
soon as you evaluate the variable, before the return is even
executed.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top