Re: the mystery of <ctrl-d>



On 29 Apr 2007 13:21:17 -0700, Bill Pursell <bill.pursell@xxxxxxxxx>
wrote:

On Apr 29, 9:12 pm, Keith Thompson <k...@xxxxxxx> wrote:
Bill Pursell <bill.purs...@xxxxxxxxx> writes:
On Apr 29, 11:31 am, chandanlinster <chandanlins...@xxxxxxxxx> wrote:
[...]
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int j;

for (j = 0; getchar() != EOF;j++)
;
fprintf(stdout, "Number of characters = %d\n", j);

exit(EXIT_SUCCESS);

It seems weird to exit() here instead of simply returning a value...

[...]

Why? Within the main() function, "exit(EXIT_SUCCESS)': and
"return EXIT_SUCCESS;" are (almost) exactly equivalent.

Just because it seems odd. It seems cleaner to return
than to exit, but there's no reason for that other than
aesthetics.

There is one reason. It prevents the compiler complaining that the
function doesn't return a value :-)

exit() feels like something that should be
reserved for an error condition.

--
Al Balmer
Sun City, AZ
.



Relevant Pages

  • Re: the mystery of
    ... Bill Pursell said: ... Just because it seems odd. ... It seems cleaner to return ... than to exit, but there's no reason for that other than ...
    (comp.lang.c)
  • Re: the mystery of
    ... Just because it seems odd. ... It seems cleaner to return ... than to exit, but there's no reason for that other than ...
    (comp.lang.c)
  • Re: the mystery of
    ... Just because it seems odd. ... It seems cleaner to return ... than to exit, but there's no reason for that other than ...
    (comp.lang.c)
  • Re: hidden in drawers - when is it obsession?
    ... If you actually think that owning anything for any reason other than for its ... immediate usefullness is odd, I think that's fine and OK for you to think ... collecting knives. ... As I have no idea what your intent is and I certainly don't intend to ...
    (rec.knives)
  • Re: FWD: Latest update on Pat "Nine Toes" Flannery
    ... No women over ten years older than you are for the same reason. ... No women whose ex-boyfriends were crazy or criminals, that should be a real good clue that there is something odd going on upstairs with them. ... as that adds a great deal of complexity to any relationship.* ... No women whose finances are in a state of constant chaos, as that indicates that your finances will also end up that way shortly. ...
    (sci.space.history)