Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!julius.cs.uiuc.edu!rpi!zaphod.mps.ohio-state.edu!lavaca.uh.edu!menudo.uh.edu!starsoft!david From: david@starsoft (Dave Lowrey) Newsgroups: comp.sys.amiga.programmer Subject: Re: How are some programs SO DAMN SMALL! Message-ID: <188e595a.ARN262e@starsoft> Date: 21 Jan 91 13:29:30 GMT References: <1991Jan20.210328.18087@hoss.unl.edu> <702@caslon.cs.arizona.edu> Reply-To: david@starsoft Followup-To: comp.sys.amiga.programmer Organization: Starbound Software Group Lines: 42 Expires: Keywords: Distribution: In article <702@caslon.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. > > >the result is 4424 bytes, OPTIMIZED and all. How can a HUGE clock compile > >smaller then a printf statement. > > > >[...] > > > >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. > True, but there IS a way to get smaller C code. You have to write your own startup code. Most compilers supply the code for their startup routine (SAS calls theirs c.c). You can copy it and modify it to take out the extra stuff. ---------------------------------------------------------------------------- These words be mine. The company doesn't care, because I am the company! :-) Dave Lowrey | david@starsoft or {uhnix1,lobster}!starsoft!david Starbound Software Group | Houston, TX | "Dare to be stupid!" -- Weird Al Yankovic