home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!paladin.american.edu!gatech!destroyer!ncar!noao!amethyst!organpipe.uug.arizona.edu!news
- From: dave@cs.arizona.edu (Dave Schaumann)
- Newsgroups: comp.lang.c
- Subject: Re: [FAQ] size of executables ?
- Message-ID: <1993Jan3.212235.1338@organpipe.uug.arizona.edu>
- Date: 3 Jan 93 21:22:35 GMT
- References: <93003.004225RVK@psuvm.psu.edu>
- Sender: news@organpipe.uug.arizona.edu
- Reply-To: dave@cs.arizona.edu (Dave Schaumann)
- Organization: University of Arizona
- Lines: 49
- In-Reply-To: RVK@psuvm.psu.edu
-
- In article <93003.004225RVK@psuvm.psu.edu>, RVK@psuvm writes:
- >How does one compile a c program so that the size of the
- >executable is as small as possible.
-
- Most compilers have various switches that effect the size of the executable
- in various ways. For instance, you may have switches to include information
- for debugging, or profiling. Debugging information, in particular, can
- greatly inflate the size of the executable. It doesn't really matter when
- you're trying to find a bug, but you should be sure that they're turned
- off when you're ready to put it into common use.
-
- Additionally, compilers typically have a switch to turn on various
- optimization routines, which typically result in a smaller as well as
- faster executable.
-
- There may also be switches that effect such things as the size of integers,
- which can also be used to reduce the size of the executable (but watch out--
- there's a lot of code out there that assume sizeof(int) == sizeof(int *)...)
-
- Beyond that, about all you can do is try different compilers, which tend to
- vary quite a bit on the quality of code produced.
-
- >I noticed that even a
- >trivial program like Hello.c produces a huge executable,
-
- I'm not sure what you consider "huge"...
-
- #include <stdio.h>
- main() { puts("Hello, world") ; }
-
- produces an executable of 24576 bytes in size on my machine (a Sun 4...)
- In my experience, programs compiled on a Sun tend to be larger than elsewhere,
- but not (completely) unreasonably so... 24+K might seem large for a program
- that simply sends a 13 byte string to the standard output, but as you
- surmize:
-
- >perhaps due to the include files stdio.h etc.
-
- This isn't quite correct... if you look at the contents of <stdio.h>, you'll
- see externs for lots of functions. The code for these functions lives in
- the "standard library", which typically gets linked in to every program you
- compile. Theoretically, there's no reason why the whole library has to be
- linked into your program when you only use a tiny piece of it... but it's
- much easier to do it that way, and given the fact that disk space and memory
- is fairly cheap, there's little motivation to do it just to save a few K off
- of a few small programs.
-
- --
- Dave Schaumann dave@cs.arizona.edu
-