home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!usenet-feed.cc.umr.edu!mcastle
- From: mcastle@cs.umr.edu (Michael R Castle)
- Subject: Re: [FAQ] size of executables ?
- References: <93003.004225RVK@psuvm.psu.edu>
- Date: Sun, 3 Jan 1993 07:14:30 GMT
- Nntp-Posting-Host: next9.cs.umr.edu
- Organization: University of Missouri - Rolla, Rolla, MO
- Sender: cnews@umr.edu (UMR Usenet News Post)
- Message-ID: <1993Jan3.071430.11936@umr.edu>
- Lines: 74
-
- In article <93003.004225RVK@psuvm.psu.edu> <RVK@psuvm.psu.edu> writes:
- >Hi, my question may be a faq, but I am asking it nevertheless.
- >
- >How does one compile a c program so that the size of the
- >executable is as small as possible. I noticed that even a
- >trivial program like Hello.c produces a huge executable,
- >perhaps due to the include files stdio.h etc. Of course,
- >I can not do any i/o without stdio.h . On the other hand,
- >I am not using all the stuff that's there in stdio.h, and
- >feel that the size of the executable should be proportional
- >to what I am using. Any suggestions ?
-
- printf() is huge. Anyprogram that uses printf() has the potential for creating
- a large exectuable.
-
- Try this:
-
- #include <stdio.h>
-
- int main(void) {
- printf("line 1\n");
- }
-
-
- then:
-
- #include <stdio.h>
-
- int main(void) {
- printf("line 1\n");
- printf("line 2\n");
- }
-
-
- Compare the size of the executables. Probably pretty close. It's not so
- much how many function calls, but what functions you are calling.
-
- I imagine puts() is much smaller than printf().
-
- Try
-
- #include <stdio.h>
-
- int main(void) {
- puts("line 1\n");
- }
-
- And see if that is any smaller than using printf().
-
- Of course, then you loose functionallity.
-
- You could try to simulate printf() functionallity using sscanf() and puts()
- but I imagine sscanf is nearly as large as printf() so you wouldn't get
- anyway. (Maybe both link in the same code?)
-
- Anyway, smart linkers (like Borlands) does try to link in only function that
- are actually called, so not all the functions listed in stdio.h are linked in.
-
- Matter of fact, man compiler (at least on unix systems) are putting more and
- more of all the prototypes into one (large) .h file. I imagine the original
- reason for not including all the of the standard system libs into one large
- file in the first place was because of slower systems. Filtering out all the
- stuff in the .h file you don't actually use was too slow. Now days, compilers
- are usually fast enough that that extra overhead is not noticable (of course,
- this limits defining your own functions that have the same name, but oh
- well).
-
- enough ramblings,
- mrc
- --
- Mike Castle .-=NEXUS=-. Life is like a clock: You can work constantly
- mcastle@cs.umr.edu and be right all the time, or not work at all
- S087891@UMRVMA.UMR.EDU and be right at least twice a day. -- mrc
- We are all of us living in the shadow of Manhattan. -- Watchmen
-