In article <11**********************@m73g2000cwd.googlegroups .com>,
kshudra <ex****************@yahoo.co.inwrote:
>Andrew Poelstra wrote:
>On Fri, 2006-10-13 at 22:51 -0700, kshudra wrote:
( ( c = getchar()) != EOF ) ? main() : putchar(c);
vs
if ( ( c = getchar()) != EOF)
main();
putchar(c);
>Both are recursive.
>please shed some light on why it is not executing putchar()
Some people have said that the first version is not recursive, but
Andrew is correct that -both- versions are recursive.
The second version executes one putchar() per invocation of main().
The first version executes one putchar() -total-, and the value
that it attempts to putchar() is EOF.
The exact value of EOF is not defined by the C standards: what
is specified, though, is that the value of EOF must be negative.
When you putchar() a value, then that is equivilent to putc() the
value to stdout, which in turn is equivilent to fputc() the
value to stdout. fputc() will take the integral value handed to it,
the negative value which is EOF, and will convert it to an
unsigned char, and will output that.
*Usually* EOF is implemented as the signed value -1, and *usually*
converting -1 to unsigned char will result in the (decimal) value 255
[but there are systems on which neither of these "usually" hold].
stdout will be a text stream if the system can prove that stdout
is associated with "a terminal". The C standard says that if
you output something to a text stream and do not output a newline
before closing the stream, that the implementation is not required
to actually output it; if stdout happens to be a binary stream
then the output must be produced even without the trailing newline,
except that trailing '\0' characters are allowed to be lost.
Putting these together: if your operating system allowed you
to redirect the C program output to a file, and you were to carefully
examine that file after executing the first program, you would see
that you did get a small amount of output: whatever
converting EOF to unsigned char came out as. It is fairly unlikely
that it will happen to be a printable character, so you might
have to use some kind of binary dump tool in order to tell that it
is there.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes