Path: utzoo!censor!geac!torsqnt!lethe!yunexus!ists!helios.physics.utoronto.ca!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!samsung!zaphod.mps.ohio-state.edu!ncar!noao!arizona!dave From: dave@cs.arizona.edu (Dave P. Schaumann) Newsgroups: comp.sys.amiga.programmer Subject: Re: How are some programs SO DAMN SMALL! Summary: It's the link files Message-ID: <702@caslon.cs.arizona.edu> Date: 21 Jan 91 00:04:08 GMT References: <1991Jan20.210328.18087@hoss.unl.edu> Organization: U of Arizona CS Dept, Tucson Lines: 44 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. As an aside, I would like to point out that unless you're writing something that is extremely time critical, or *every* *byte* *counts*, writing a whole program in assembly is probably overkill. Masochists & obsessives are, of course, exempt. Real time simulations are a good example if the former, and utilities that are permenantly resident (like a system clock) or used frequently are good examples of the latter. > "These are not ASUN's, DN's, or Phil Dietz > the Regent's opinions. Therefore 231b3678@fergvax.unl.edu > they aren't full of 'filler.'" Univ. of Nebraska Python disclaimer: "It was one of Wilde's!" Dave Schaumann | And then -- what then? Then, future... dave@cs.arizona.edu | -Weather Report