Don't use Scanf()

Karl Heuer karl at haddock.ISC.COM
Wed Mar 16 05:33:20 AEST 1988


In article <1140 at csun.UUCP> sef at csun.UUCP (Sean Fagan) writes:
>printf("Hello world!\n") is slower than puts("Hello world!") which is slower
>than write(1,"Hello world!\n",13).

Using write() instead of the stdio routines is not necessarily a win, because
non-UNIX systems may still have to fiddle with e.g. NL vs. CRLF conversions.
Also note that (even on UNIX) the buffering which is usually done in stdio may
let you write everything with a single system call; this can make stdio faster
than multiple calls to write().

>For the most part, I don't include <stdio> in my programs at all; printf
>doesn't need it, and I can get by with write very easily.

I once used a compiler that let me use stdin, stdout, stderr without including
<stdio.h>.  I included it anyway, because I knew that omitting it was not
portable.  If your implementation lets you use printf without <stdio.h>, fine,
but don't complain too loudly if you try to port your code and it suddenly
stops working.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list