Re: the mystery of <ctrl-d>
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Sun, 29 Apr 2007 14:23:51 -0700
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"
.
- References:
- the mystery of <ctrl-d>
- From: chandanlinster
- Re: the mystery of <ctrl-d>
- From: Bill Pursell
- Re: the mystery of <ctrl-d>
- From: Keith Thompson
- Re: the mystery of <ctrl-d>
- From: Bill Pursell
- the mystery of <ctrl-d>
- Prev by Date: Re: Ahead of "main"?
- Next by Date: Re: Ahead of "main"?
- Previous by thread: Re: the mystery of <ctrl-d>
- Next by thread: Re: the mystery of <ctrl-d>
- Index(es):
Relevant Pages
|
|