Don't use Scanf()

Matthew Belmonte belmonte at svax.cs.cornell.edu
Sun Mar 13 16:09:41 AEST 1988


In article <9241 at sunybcs.UUCP> ugfailau at sunybcs.UUCP (Fai Lau) writes:
>	C'mon!!! Is it really an issue?

It shouldn't be.  This discussion reminds me of a time a few years ago when I
was living near Washington, D.C. and someone on a local BBS decried the use of
comments in source code because they increase compilation time.

>In article <1185 at ucsfcca.ucsf.edu> roland at rtsg.lbl.gov (Roland McGrath) writes:
>>For example:
>>	printf("Hello world!\n");
>>Haven't you ever heard of puts????
>>	puts("Hello world!");	/* note the newline is appended	*/
>
>	I can't imagine any reasonably competant [sic] C compiler not
>generating the almost same codes for both cases.

Imagine again.  The generated code will be a push of the address of the argument
(in the above examples, a constant string) onto the stack, followed by a
jump-to-subroutine to the called function, either _printf or _puts.  Thus, the
object codes are completely disparate.  But this doesn't alter the fact that
IT JUST DOESN'T MAKE ENOUGH DIFFERENCE FOR THE PROGRAMMER TO CARE.  printf and
puts are both linear-time algorithms.  printf probably takes a little longer
because it has to check for embedded format strings, but it doesn't find any in
this case, so the extra time is negligible.  As for the space, someone already
mentioned that the effect of chopping out library routines such as _printf is
usually swamped by the effect of the operating system's block allocation scheme.
Program images take constant space.  It's only the data space that can get
larger with problem size, and that's what you should be concerning yourselves
with.

There are some things worth devoting your time to, and there are other things
better left alone.  These are sometimes difficult to differentiate, but not in
this case.  YOU PEOPLE ARE NITPICKING.
-- 
Matthew Belmonte
Internet:	belmonte at sleepy.cs.cornell.edu
BITNET:		belmonte at CRNLCS
*** The Knights of Batman ***
(Computer science 1, College 5, Johns Hopkins CTY Lancaster '87 session 1)



More information about the Comp.lang.c mailing list