Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!lll-winken!elroy.jpl.nasa.gov!usc!wuarchive!kuhub.cc.ukans.edu!markv From: markv@kuhub.cc.ukans.edu Newsgroups: comp.sys.amiga.programmer Subject: Re: How are some programs SO DAMN SMALL! Message-ID: <28077.279c3c3f@kuhub.cc.ukans.edu> Date: 22 Jan 91 19:21:02 GMT References: <1991Jan20.210328.18087@hoss.unl.edu> Organization: University of Kansas Academic Computing Services Lines: 52 > the result is 4424 bytes, OPTIMIZED and all. How can a HUGE clock compile > smaller then a printf statement. Assembler has a lot to do with it. A C compiler pulls in a lot of code for run time support. > What are steps to compile the smallest Lattice code? Here are the few that I > know. > > 1) Use protos and include files whenever possible. > 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. > 4) Compile with -Lvrt -curfist -rr -mat -O -b1 file to create registerized > code. Well, you can cheat quite a bit. Write all your I/O to use Amiga system lib funcs. Rewrite the startup to be bare bones and not pull in things. Play with the preprocessor. I have a file "mystdio.h" that I include after stdio.h that includes things like: #define puts(s) {Write(Output(), s, strlen(s));} This gets pretty efficient assuming an inline strlen. Things like sprintf(), fprintf(), etc (w/o fancy formatting) can be emulated using RawDoFmt() and Write(). Fopen can be done with things like: #define "w" MODE_NEWFILE #define "r" MODE_OLDFILE #define fopen(f, m); Open(f, m); Note that doing things like this you loose the support you get from the normal C library like buffering, auto file closing, etc. Modes like "w+", etc require more work but are possible. > 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. See how small it gets if you use AmigaDOS functions like Examine(), ExNext(), Write()) and system support, RawDoFmt(), etc instead of C lib functions like printf(), dnext(), etc. -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mark Gooderum Only... \ Good Cheer !!! Academic Computing Services /// \___________________________ University of Kansas /// /| __ _ Bix: markgood \\\ /// /__| |\/| | | _ /_\ makes it Bitnet: MARKV@UKANVAX \/\/ / | | | | |__| / \ possible... Internet: markv@kuhub.cc.ukans.edu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~