Re: the mystery of <ctrl-d>
- From: Al Balmer <albalmer@xxxxxxx>
- Date: Sun, 29 Apr 2007 23:26:45 GMT
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
.
- 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: Encrypting only with Kernel Functions
- Next by Date: Re: String Comparision
- Previous by thread: Re: the mystery of <ctrl-d>
- Next by thread: Re: the mystery of <ctrl-d>
- Index(es):
Relevant Pages
|