Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!rutgers!bellcore!flash!sdh From: sdh@flash.bellcore.com (Stephen D Hawley) Newsgroups: comp.sys.mac.programmer Subject: dead code, brain dead lilbrary Message-ID: <20062@bellcore.bellcore.com> Date: 15 Feb 90 20:17:16 GMT References: <1990Feb14.204332.24800@caen.engin.umich.edu> Sender: news@bellcore.bellcore.com Reply-To: sdh@flash.UUCP (Stephen D Hawley) Organization: Bellcore, Morristown, NJ Lines: 94 In article <1990Feb14.204332.24800@caen.engin.umich.edu> billkatt@mondo.engin.umich.edu (billkatt) writes: >Think C DOES indeed remove dead code, ever since version 3.0. It doesn't seem >to do quite as good a job as MPW 3.0, but a good job none the less. To >remove dead code, just check the 'Smart Link' check box when you build your >app/DA/whatever. You can go out and prove it to yourself by writing a >program which uses one small routine from the ANSI library, and building it to >disk. Whereas the ANSI library is 27K long, your program will come out to >about 5 or 6K. > >-Steve Bollinger Yes, it removes dead code, but the ANSI library is pretty darn stupid when it comes to the atomicity of the libraries. Ok, quiz question: How many of you can write/have written atoi()? How many lines was it for you? A whopping 12 or 13? Here's what Think C 4.0 uses in the library: atoi(s) char s; { int n; if (sscanf(s, "%d", &n)) return(n); else return(0); } One atoi() has just destroyed me in terms of application size. Have you seen what sscanf() brings in with it? Yuck. I was so appalled by this and the general performance of the library that I took a week and implemented a subset of the standard i/o package that includes putc(), fputc(), getc(), fgetc(), puts(), fputs(), printf() (small version - no float support), fprintf(), sprintf(), fopen(), fclose(), fread(), fwrite() and more. You can make any number of windows to printf() to. To get input, you do an fopen() with the magic file name "/dev/keyboard". You get window updates for free, and it's faster than than Think C's library, and it supports text selection and copy/paste operations. How much memory would you sacrifice for such a beast? 10K? 15K? 27K? Nope. 5.5K Yes, I have a few regrets. It should really make window objects be streams sothat printf (actually called Wprintf()) is the same as fprintf(), and it should have better font support, but remember I put this together in a week. I know Think C's ANSI library has a huge amount of content, but I think some better attention should be given to its organization so I don't buy the farm for atoi(). Why, oh why couldn't atoi() look like this: #define isDigit(c) ((c) >= '0' && (c) <= '9') #define isWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n') /* This is for notational convenience, so we bring in all the ctype tables. * Beware of side effecting c */ int atoi(s) register char *s; { register int val, sign; /* * The Berkeley UNIX manual states that atoi will read an optional * number of spaces --we read an optional amount of white space, * ie, space, tab, return, newline. The byte conscious can make * this just use space. */ while(isWhite(*s)) s++; val = 0; sign = 1; if (*s == '-') { sign = -1; ++s; } while(isDigit(*s)) { val = 10 * val + *s - '0'; } return(val * sign); } Steve Hawley sdh@flash.bellcore.com A noun's a special kind of word. It's ev'ry name you ever heard. I find it quite interesting, A noun's a person place or thing.