earleh@eleazar.dartmouth.edu (Earle R. Horton) (10/05/88)
In the MPW C manual, it states that you cannot use sprintf() without getting C standard IO functions loaded. This amounts to very roughly 10k worth of dead code in a program that uses sprintf() or sscanf() but does file IO through the ToolBox routines. I discovered this after I added to a program the capability to display floating point values in a window: The final application size jumped way up after adding one or two calls to sprintf(). After messing around with dumpobj and {clibraries}stdclib.o, I have discovered that sprintf() calls _doprnt(), which calls _flsbuf() and fwrite() when called by fprintf(). Likewise, sscanf() calls _doscan(), which calls _filbuf() when called by fscanf(). If you want to use sprintf() or sscanf(), then, but don't want standard IO loaded, you can get around the unwanted references in _doprnt() and _doscan() by adding stub functions to satisfy the linker, and linking the object file which contains them before the C libraries in your linker command line: stubs.c: fwrite(){} _flsbuf(){} _filbuf(){} link stubs.c.o {rest of junk} -o {program} Of course, this could get hairy if you inadvertently type "scanf" instead of "sscanf." (I have done this many times.) It might be a good idea then to have your stub functions throw up your favorite "programmer alert" box and maybe longjmp() back to your main routine, or something equally appropriate. If you do use standard IO in Macintosh applications, please disregard the above message. Earle R. Horton. 23 Fletcher Circle, Hanover, NH 03755 (603) 643-4109 Sorry, no fancy stuff, since this program limits my .signature to three