Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool2.mu.edu!uunet!cbmvax!andy From: andy@cbmvax.commodore.com (Andy Finkel) Newsgroups: comp.sys.amiga.programmer Subject: Re: How are some programs SO DAMN SMALL! Message-ID: <17876@cbmvax.commodore.com> Date: 22 Jan 91 01:55:17 GMT References: <1991Jan20.210328.18087@hoss.unl.edu> <702@caslon.cs.arizona.edu> Reply-To: andy@cbmvax.commodore.com (Andy Finkel) Organization: Commodore, West Chester, PA Lines: 49 In article <702@caslon.cs.arizona.edu> dave@cs.arizona.edu (Dave P. Schaumann) writes: >In article <1991Jan20.210328.18087@hoss.unl.edu> 231b3678@fergvax.unl.edu (CS 231 section 2) writes: >>I was looking through some programs that were written in C, and I noticed that >>a few were really SMALL! Like only 2k for a full-blown clock. How does the >>program get so small! It seems that if I compile a program like >> >>#include >>main(){printf("hey man!\n");} > >The reason even a minimal C program, ie "main(){}" compiles to ~4K is that it >you have to link it to the run-time library. This has code for stuff like >parsing the command line, and setting up stdin/stdout. If you had something >like "main(){real x; x = 0.0;}", it would be even larger, because now you >would be bringing in all the f.p. routines as well. >>Can 'C' code get small? I have a LIST program in the works. It's 14000 >>bytes compared to c:list's 2500. Assembly must be the only decent way to >>go. > >As you guessed, if you want *really* small code, you have to use assembler. >Then you only have the code you need to run your program, and no extra hidden >stuff. > Well, actually, the 2.0 commands in the C: directory are written in C, not assembler. The reason we can get so small is: 1) we compile without a startup. For a small command, often the startup is a major part of the program itself. Because these commands get called in a CLI environment, we can make certain assumptions, and do without a startup. 2) We use 2.0 AmigaDOS calls (ReadArgs() ) to parse the command line andy -- andy finkel {uunet|rutgers|amiga}!cbmvax!andy Commodore-Amiga, Inc. "God was able to create the world in only seven days because there was no installed base to consider." Any expressed opinions are mine; but feel free to share. I disclaim all responsibilities, all shapes, all sizes, all colors.