Path: utzoo!attcan!uunet!ogicse!jmeissen From: jmeissen@ogicse.ogi.edu (John Meissen) Newsgroups: comp.sys.amiga.tech Subject: Re: Writing small code in SAS/C 5.10 Message-ID: <12482@ogicse.ogi.edu> Date: 28 Sep 90 22:03:20 GMT References: <13148@leadsv.UUCP> Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR Lines: 41 In article <13148@leadsv.UUCP> lord@leadsv.UUCP (Parker Lord) writes: >I wrote myself a unix like 'mv' command because the AmigaDOS rename seemed >to limited. My problem is that the linked code comes out to be about 9K. >I used the SD SC ND flags with Blink. I thought that this was rather large >for the amount of code actually written so I tried a test. I wrote a one line >program that does nothing more than a printf("Hello\n"); I compiled and linked >this using lc -L. This code came out at about 4.6K. In comparison, the >AmigaDOS rename command is less than 1K and the ARP mv command is about 1K. >Are there some general guidelines to follow to make linked code smaller? >I also invoked the global optimizer with lc, but that didn't help at all. Aaaack! This is one of my pet peeves! Does anybody out there have ANY idea how much work printf() does and how large it is? If you want to write the largest program possible for printing a string, use printf()! Please, please, please don't use printf() for size comparisons. The reasons for the large code size are 1.convenience, 2.unix compatibility, and 3.library code. By DEFAULT, you have buffered file I/O for stdin, stdout, and stderr set up for you. THere's also code that will open a console window if you're running under Workbench. There's code that sets up the run-time environment (stack, arguments, whatever), tracks memory allocation and file usage (Unix style). The secret is to use the MAP option of blink. Look at where the memory is going, figure out what's being called and why, and then figure out a different way of doing things that doesn't have that effect. Also, check out c.a and umain.c. If you can, get a copy of the NagRag from December 1989 and Jan-Feb 1990 (Newsletter of the Northwest Amiga Group, P.O. Box 1140, Oregon City, OR 97045). I wrote a 3-part series on how to trim the excess from your Lattice C programs. -- John Meissen .............................. Oregon Advanced Computing Institute jmeissen@oacis.org (Internet) | "That's the remarkable thing about life; ..!sequent!oacis!jmeissen (UUCP) | things are never so bad that they can't jmeissen (BIX) | get worse." - Calvin & Hobbes