Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!warwick!estdwha From: estdwha@warwick.ac.uk (CrisP) Newsgroups: comp.sys.amiga.programmer Subject: Re: How are some programs SO DAMN SMALL! Message-ID: <1991Jan21.012040.25817@warwick.ac.uk> Date: 21 Jan 91 01:20:40 GMT References: <1991Jan20.210328.18087@hoss.unl.edu> Sender: news@warwick.ac.uk (Network news) Organization: Computing Services, Warwick University, UK Lines: 56 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 result is 4424 bytes, OPTIMIZED and all. How can a HUGE clock compile >smaller then a printf statement. Have you tried writing printf()? printf is not a simple statement. It is for formated output. The string you give it is not the string to be written but the format of the string to be written. The code to do the formatting is not small. puts() is what you should replace all printf()'s with only one argument with. > >What are steps to compile the smallest Lattice code? Here are the few that I >know. > >1) Use protos and include files whenever possible. Using protos and includes is just good programming practice. It won't reduce the size of your code. >2) Utilize .library calls when possible and don't forget to OPEN it so > the pragmas dont go to waste. >3) Try not to use printf and any amiga.lib function for the matter. Actualy amiga.lib contains both the c.lib functions and stubs for the system library call suct as Open() in the DOS library. >4) Compile with -Lvrt -curfist -rr -mat -O -b1 file to create registerized > code. The only other thing is that you can use _main() inseted of main(). This get rid of all the startup waffle needed for the c libaray routines. such as read, write, malloc, free and anything that uses them. Note that the workbench startup waffle also accurs in _main(). The DOS and Exec libraries are Open'd before _main(). > >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. > >Phil Dietz Yes thay can. Try _main() { Write(Output(), "hay man!\n", 9L); } ~CrisP. -- ----------------------------------------------- crisp@uk.ac.warwick.cs estdwha@uk.ac.warwick.cu