printf() problem

Kevin Franden kevinf at infmx.UUCP
Fri Apr 28 08:09:10 AEST 1989


In article <518 at cpsc6b.cpsc6a.att.com> crs at cpsc6b.cpsc6a.att.com (Chris (I'm Outta Here!) Seaman) writes:
>zougas at me.utoronto.ca ("Athanasios(Tom) Zougas") writes:
>< jdm at hodge.UUCP (jdm) writes:
>< >    Perhaps someone could explain this printf() phenomena to me.
>
>[printf example deleted...]
>
	[other stuff deleted...]

>< What you did will correct it. Or try:
>< 
>< 	for ( i = 0; i < 4; ++i ) {
>< 	    printf( "%x ", getc(fp) );
>< 	}
>< 	printf( "\n" );
>< 
>< Of course, where you are gaining in not having to declare 4 variables,
>< you are losing in 5 calls of printf. Trade-offs, trade-offs ...
>
>I hope this doesn't start a flame war, but IMHO, you should NEVER use
>a function with all the overhead of printf() to output a simple linefeed.
>putchar() or fputc() would do the same job, without all the overhead.
>
	Um.... isn't the last printf "for free" 'cause it's already
	linked in from the other call?  Once you call a routine it doesn't
	matter how MANY times you call it, right?

	I agree that it would be better to use puts(" ") or somthing 
	(anything!) with less overhead to do such a trivial operation
	like printing a NL, but if you already used the (big, complex) 
	code of printf, why not reuse it?   Unless you're REAL concerned 
	about saving clock cycles (puts being faster)...





-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Kevin Franden		    UUCP: {backbone}!pyramid!infmx!kevinf
Informix Software Inc
disclaimer("I said what I said and not my employer");
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the Comp.lang.c mailing list