Xref: utzoo comp.sys.m6809:718 comp.lang.c:8198 Path: utzoo!mnetor!uunet!husc6!cca!g-rh From: g-rh@cca.CCA.COM (Richard Harter) Newsgroups: comp.sys.m6809,comp.lang.c Subject: Re: Don't use Scanf() Message-ID: <25547@cca.CCA.COM> Date: 15 Mar 88 11:37:01 GMT References: <2401@ihwpt.ATT.COM> <320@c10sd1.StPaul.NCR.COM> <1185@ucsfcca.ucsf.edu> <9241@sunybcs.UUCP> <1140@csun.UUCP> Reply-To: g-rh@CCA.CCA.COM.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge, MA Lines: 35 Keywords: C stdio library Re: Should one use puts versus always using printf. Some years ago someone (I don't have a reference anymore) took a fortran compiler and modified it to compile formatted writes rather than interpreting them. The gains in execution time were modest, on the order of 1-2%, at best. Corresponding gains can be expected in C. While it is true that using puts rather than printf when applicable is faster, the execution time efficiency gained is not particularly important. As a matter of programming style, it is preferable (all other things being equal) to use a single standard mechanism rather than a variety of mechanisms. It makes programs more complicated to write, maintain, and read if a variety of mechanisms are used for the same function. This is a simplicity versus execution time tradeoff. In our situation (SMDS not CCA) portability is an issue. By policy we restrict the use of library routines to a minimum -- the only library functions which are not carefully isolated are printf and fprintf. If I don't use puts() I don't have to know whether it runs the same and interacts the same with printf() on all machines and operating systems that we deal with. This policy is reasonable for out situation; it is not necessarily relevant for others. I would also note that if execution time for I/O is truly a concern (and it sometimes is) then one should look at doing formatting by hand, i.e. building output lines directly and writing whole lines only. In summary, this is one of those little efficiencies that is not worth bothering about in most applications. -- In the fields of Hell where the grass grows high Are the graves of dreams allowed to die. Richard Harter, SMDS Inc.