Thread: Large exe files for small amounts of code problem

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    29

    Large exe files for small amounts of code problem

    I am using DevC++ (mingw32 port of gcc I believe, version 3.2) and when ever I compile a program using the iostream library the exe is usally around 440Kb, while using stdio it is only like 26Kb. Is this normal, if not can anyone tell me the setting on how change this? Thank you in advance for your help.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    cout <<"When this program is compiled the exe is around 440KB.";
    return 0;
    }
    Code:
    #include <stdio.h>
    
    int main()
    {
    printf("When this program is compiled the exe is around 26KB.");
    return 0;
    }

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Wow that seems to be a poor compiler based on this example as it compiled for me with Borland to 112kb.

    Anyhow, the massive size of the executable is not a result of including iostream, rather it is from calling cout. There is a lot more overhead involved in all of the classes and templates and the overall hierarchy involved in the standard classes such as iostream, whereas calling printf() requires a simple function call.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Is this normal, if not can anyone tell me the setting on how change this?
    First off, the C++ standard library is much more capable than the C standard library, so you're going to get more stuff linked into your executable as a baseline. A developing C++ program should grow more slowly than the same C program, since more of the basic stuff is already present.

    Second, did you compile with debug? Debug information is stored in the executable, and C++ debug is more verbose than 'equivalent' C debug.
    You could see if you have the 'strip' utility (usually part of most gcc based distributions)
    eg
    strip prog.exe

    This removes all debug and leaves you with just the actual code. Then compare sizes.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    29
    Thankyou for the help, now the programs are half their original size.

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    And if you want it even smaller... try UPX.

    I compressed a "strip"ed simple hello world down to 72k.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with my morse code program
    By justin87 in forum C++ Programming
    Replies: 1
    Last Post: 10-21-2007, 05:23 PM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Replies: 12
    Last Post: 06-08-2005, 11:23 AM
  4. Merging files (code included)
    By TankCDR in forum C Programming
    Replies: 3
    Last Post: 10-28-2001, 11:06 AM
  5. Big Code, Little Problem
    By CodeMonkey in forum Windows Programming
    Replies: 4
    Last Post: 10-03-2001, 05:14 PM