In article <>
Herbert Kleebauer <> wrote:
>Now GCC disappoints me. Just compiled the two line C program:
>
>#include <stdio.h>
>main() {putchar(10);}
[assembly snipped]
>This means, for each putchar() in the source, _IO_putc is called.
It is possible that any putchar() calls _IO_putc(), but the above
does not show this (even if you put back the assembly that I
snipped). The reason is that 10 happens to be equal to value of
'\n' on this system, and putchar('\n') must push the output to the
system if the stream in question is line-buffered. Since stdout
is very often line-buffered, one should expect putchar('\n') to
make an O/S call very often as well, and an implementation-specific
function like _IO_putc() is a good place to hide the test for
whether the call is needed, along with the call itself.
On the other hand, putchar('x'), for instance, could be done without
making a function call (since 'x' is clearly not a newline).
Similarly, a source-code construct like putchar(c), where c is a
variable rather than a known-constant newline, might expand to code
that tests whether c=='\n', then buffers c or calls _IO_putc(c) as
appropriate. (As someone suggested in another follow-up, one might
need to turn off thread support to see this, too.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out)
http://web.torek.net/torek/index.html