Why you should use puts(3) when you don't need printf(3)
Ray Lubinsky
rwl at uvacs.CS.VIRGINIA.EDU
Mon Mar 14 11:56:38 AEST 1988
True, if you use fprintf(3) (or printf(3) or sprintf(3) for that matter) once
in a program, you have paid the penalty in terms of code size. And true, if
you also use fputs(3) then you have added a little more size to your binary.
But what ever happened to run time-efficiency? The point of using fputs(3) is
that it just pushes bytes to the output! Fprintf(3) has to scan it's first
argument and gyrate around to get to the point where it pushes bytes. The
run-time size of fprintf(3) is just plain bigger. To give you an idea of the
relative sizes, on my VAX 11/780 running 4.3 BSD, fputs is implemented as 60
lines of assembly code whereas _doprnt (the function that *printf calls --
another bit of overhead) is 396 lines.
OK -- I'm not saying that using *printf where *puts is appropriate is going to
break the bank. But it's good practice to only use what you need; anything
else is just lazy programming.
More information about the Comp.lang.c
mailing list