ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/04/15/11:15:07

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
From: "Goh, Yong Kwang" <gohyongkwang AT hotmail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Creating small-sized EXE
Date: Mon, 15 Apr 2002 14:45:45 +0800
Organization: Singapore Telecommunications Ltd
Lines: 72
Message-ID: <a9eqki$9s9$1@violet.singnet.com.sg>
NNTP-Posting-Host: hs1121.singnet.com.sg
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I've noticed that the simple program that I write when compiled are way much
larger than other people's program with similar capabilities and function,
possibly compiled with other C compiler. For example, for a simple Hello
World program,

#include <stdio.h>

    printf("Hello World\n");
    return 0;

when compiled using DJGPP gcc, comes up to about 80KB. When checking out the
binary utilities supplied with DJGPP, I come across merge.exe and split.exe.
Both took up only about 30KB each. As a test I wrote a C program (I simply
call it FileJoin) to do the same thing as merge.exe (with slight differences
in the way parameters are arranged) and it ends up as a 80KB EXE, more than
2x the size of merge.exe! Notice the difference? 2 programs with almost
similar capabilities but with a huge difference in size? Why so? A quick
check of the djgpp/bin and /windows/command directory throws up lots of
programs which do more useful things and with a lot more sophistication than
my humble HelloWorld or FileJoin program and many of them are still smaller
in size. I'm sure you would agree that XCOPY.EXE (30KB), CWSDPMI.EXE (20KB),
GO32-V2.EXE (62KB) all does sophisticated stuffs and they're still small in
size. Size does matter ;) after all and I'm always impressed by small and
nimble command-line programs that load fast and do their work fast, instead
of showing me eye-candies like full color icons, transparent buttons,
animated windows with drop shadows or a bother-some agent with speech
synthesis offering "help" in the corner. Looks fun at first, but you get
weary after an hour or so.

A lot of people argues that the overhead (standard library routines plus the
stub) is of little concern as disk space is cheap nowadays with 40GB hard
disks and as the program gets bigger, the proportion of the starting
overhead to the actual program code is minimal, so what's a few KB? However,
I'm still concern that a simple program doing a simple task should not be
unnecessarily big -- the size has to be in proportion to what a program can
accomplish. IMHO, I consider anything that uses up more computing resources
than what it *should* require a bloatware. Why would we need 80KB just to
print only "Hello World" on the screen? Yes disk space and memory is cheap
but not free or infinite. I just want to cultivate the habit of writing
compact and speedy code instead of hogging unnecessary resources. 1 or 2
bloatware programs are probably fine but consider this for DOS
Terminate-Stay-Residents, Unix daemon processes or Windows services, with
probably a hundred of them residing in memory in the background and forking
out more processes as they're activated, the computer will be struggling
under all these over-sized programs and we take a performance hit. Just my
opinion. Please don't flame or "attack" me.

I wonder if the problem lies with my program design or programming style? Or
is it that I've not instructed gcc via some switches, which apparently I'm
not aware of, to do code optimization for generation of compact code,
leading gcc to include some debugging info in the EXE?

And any tips to reduce EXE size to the minimum, for example, by not linking
in unused routines/libraries etc and by changing program design etc? And is
it time I should start learning x86 assembly language programming instead of
mucking around in C/C++ :=)?

Yong-Kwang Goh
gohyongkwang AT hotmail DOT com

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.344 / Virus Database: 191 - Release Date: 4/2/02

- Raw text -

  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019