Re: the mystery of <ctrl-d>



Bill Pursell <bill.pursell@xxxxxxxxx> writes:
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. exit() feels like something that should be
reserved for an error condition.

Ok, so it's a matter of style -- and one on which the authors of the
standard disagree with you, or they wouldn't have included the
EXIT_SUCCESS macro.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



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 ... There is one reason. ...
    (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)
  • porting problem
    ... Socket.h:47: parse error before `)' ... Socket.h:46: conflicts with previous declaration `int Socket::sending' ... Socket.cpp:33: ANSI C++ forbids declaration `memset' with no type ... Socket.cpp:38: ANSI C++ forbids declaration `exit' with no type ...
    (comp.unix.programmer)
  • Re: how to remove code duplication
    ... A programs that will take input from stdin and put that into log files. ... void create_logname(char *, int); ... exit(EXIT_FAILURE); ...
    (comp.lang.c)