Xref: utzoo comp.sys.m6809:716 comp.lang.c:8195 Path: utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!dcc1!emcard!fedeva!csun!sef From: sef@csun.UUCP (Sean Fagan) Newsgroups: comp.sys.m6809,comp.lang.c Subject: Re: Don't use Scanf() Message-ID: <1140@csun.UUCP> Date: 13 Mar 88 02:56:06 GMT References: <2401@ihwpt.ATT.COM> <320@c10sd1.StPaul.NCR.COM> <1185@ucsfcca.ucsf.edu> <9241@sunybcs.UUCP> Reply-To: sef@csun.UUCP (Sean Fagan) Organization: CSU, Northridge Sun Computer Lines: 59 Keywords: C stdio library In article <9241@sunybcs.UUCP> ugfailau@sunybcs.UUCP (Fai Lau) writes: >In article <1185@ucsfcca.ucsf.edu> roland@rtsg.lbl.gov (Roland McGrath) writes: [regarding uses of printf(3)] > C'mon!!! Is it really an issue? Yes, it can be; since printf(3) is interpreted, it *WILL* be slower than directly coding the correct statements. I.e., printf("Hello world!\n") is slower than puts("Hello world!") which is slower than write(1,"Hello world!\n",13). If you're doing a lot of I/O like this, it can be significantly slower. >>For example: [printf vs. puts] > I can't imagine any reasonably competant C compiler not >generating the almost same codes for both cases. What does a compiler have to do with a *subroutine*?! printf is a subroutine, just like any other; the compiler knows nothing about it, nor should it. (As an aside, I've thought about writing a printf compiler, but has anybody else already done that? The generated code would be larger, but, most likely, quite a bit faster...) > should be included in mostly every program >just so that when you do need it you have it around. It's not >gonna give you a bigger or slower program. No, but it does eat up namespace, typedef space, you're precluded from using your own putc, getc, etc., etc. >>And the ultimate stupidity: >> printf("\n"); >>Get a brain!!!!! You're using the function that can do complex >>data formatted output to write one bleeping character!!!!! >>Try >> putchar('\n'); >>If you include , this will probably end up being a macro >>that will write it out very fast. [sprintf(buf, "constant string"); instead of strcpy] > Let's face it. The best way to give efficiency to a program >is to write your own macro to handle file I/O and strings. Macros like >strcpy are too general if you want to be picky. [write own routine using putc for fast I/O] No, if one wants to do that, one doesn't use at all; one uses write(2) (assuming you're on Unix; however, most PC C compilers support write anyway). For the most part, I don't include in my programs at all; printf doesn't need it, and I can get by with write very easily. >Fai Lau >SUNY at Buffalo (The Arctic Wonderland) >UU: ..{rutgers,ames}!sunybcs!ugfailau >BI: ugfailau@sunybcs INT: ugfailau@joey.cs.buffalo.EDU -- Sean Fagan uucp: {ihnp4,hplabs,psivax}!csun!sef CSUN Computer Center BITNET: 1GTLSEF@CALSTATE Northridge, CA 91330 (818) 885-2790