Compiler: Size of generated executable file

bearophile bearophileHUGS at lycos.com
Mon Jan 11 04:12:14 PST 2010


Walter Bright:
> Optlink does this too. It's oooollldd technology, been around since the 
> 80's. Consider the following program:

Only now GCC is starting to do it, and only partially. If you compile that C example (3 files):

--- a.h ---
extern int foo1(void);
extern void foo2(void);
extern void foo4(void);
--- a.c ---
#include "a.h"

static signed int i = 0;

void foo2(void) {
 i = -1;
}

static int foo3() {
foo4();
return 10;
}

int foo1(void) {
int data = 0;

if (i < 0) { data = foo3(); }

data = data + 42;
return data;
}

--- main.c ---
#include <stdio.h>
#include "a.h"

void foo4(void) {
 printf ("Hi\n");
}

int main() {
 return foo1();
}

All you find at the end is a binay that contains the compile of just:

int main() {
    return 42;
}

All other constants, variables and functions are absent. I'm sure it's not rocket science, but such things do actually improve performance of programs, sometimes in my tests up to about 15-25% (with the help of inlining too).

Bye,
bearophile



More information about the Digitalmars-d mailing list