Compressing C programs

D'Arcy J.M. Cain darcy at druid.uucp
Mon Jan 8 03:18:41 AEST 1990


In article <18731 at netnews.upenn.edu> ferris at eniac.seas.upenn.edu.UUCP (Richard T. Ferris) writes:
>I am interested in learning how to reduce the size of my TurboC
>programs.  The .exe files are 13K even for very simple programs.
>Could someone send me some suggested references?  Thanks.
>

I have the following flags (among others that don't have to do with code
optimization) in my TURBOC.CFG file:

-v-              Source level debugging off
-Z               Optimize register usage
-r               register variables

I'm not sure what you mean by very simple but here are two test programs:

PROGRAM 1: (Include standard I/O)
#include	<stdio.h>
main()
{
	printf("Hello, world\n");
}

PROGRAM 2: (Ultra minimal)
main()
{
	int x = 1;
}

The executables come out to 6544 for (1) and 2310 for (2).  This tells us
what we knew all along, that code size is often affected by what is pulled
in by the standard libraries, especially standard I/O.  

You might also try the above flags (especially -v-) to save a few bytes.

Note that this assumes that you are compiling with TCC, not the environment.
I usually develop code in the environment and the delete all the objects
and re-compile with TCC.  You can do similiar things in the programming
environment.

-- 
D'Arcy J.M. Cain (darcy at druid)     |   Thank goodness we don't get all 
D'Arcy Cain Consulting             |   the government we pay for.
West Hill, Ontario, Canada         |
No disclaimers.  I agree with me   |



More information about the Comp.lang.c mailing list