Thread: exe file size

  1. #1
    Unregistered
    Guest

    Exclamation exe file size

    When I compile the following code with Dev-C++ 4.01, the file exe file size is 3072 bytes...

    #include <stdio.h>

    int main()
    {
    puts("Hello, World!");
    return 0;
    }

    When I compile the next bit of code with the same compiler, the resulting exe file size is 73728 bytes!!...

    #include <iostream.h>

    int main()
    {
    cout << "Hello, World!";
    return 0;
    }


    What good is C++ over C, when you get such bloated exe files ??!!...

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    I always use C.

    Usually ANSI. So others can use my code.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    For most computers these days, "bloat" is nothing to be concerned about. Memory is so stupidly inexpensive, and processors are so fast, this is a non-issue.

    What you're doing there is potentially two entirely different things. All you see is the fact that you've got the same number of visible lines of code.

    Consider this: What is in each of those headers? What header files do each of those reference? What libraries are linked?

    I could do this:

    #include "myheader.h"

    or

    #include "another.h"

    And have HUGELY different .exe file sizes, simply because from what is visible to you, you have no idea what my headers reference. Tell me, from looking at those lines, what one will produce the bigger .exe file? You can't. There is no way of knowing what either of those reference.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    imo cout does waste more memory than printf, for some reason or another. but i agree with
    "bloat" is nothing to be concerned about

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Nod. It's possible for you to really be concerned with if you're writing for an embedded system or something. But in general, for everyday use, it's nothing much to worry about.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Unregistered
    Guest

    Similar Theme

    On a similar note, while writing executables for a DOS Boot Disk (where size is a concern) I have found that a Win32 compilation for XP takes up only 5KB, but the same compilation for real mode DOS (using DJGPP) takes 87KB, not including the DPMI file that has to exist on the floppy. What is THAT all about?

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    197

    ANSI-C code is more universal than C++ code !!

    I prefer C, because it has only the features you really need.
    The rest is in the libraries or you can program it by your own.
    Because of these reasons C can be also used for programming other systems than a PC that havenīt so much memory (or speed).
    The cout<< function is maybe more comfortably, but not as effective as printf().

    klausi
    When I close my eyes nobody can see me...

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Win32 compilation for XP takes up only 5KB
    Probably because the .exe contains only your code, and a number of links to a dynamic library (which could be quite large), and the symbols are resolved at run time.

    >real mode DOS (using DJGPP) takes 87KB,
    Because it is a complete program, it does not require the rest of XP to be there in order to run.

  9. #9
    Unregistered
    Guest
    I think C++ and object oriented programming is some form of big brother govermental control or something. C++ has taken the C language in the wrong direction. I believe that it must always be the goal of programmer to write the tightest, fastest possible code that can be achieved. You can do this better in C than C++.

  10. #10
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    I donīt think itīs so extremely, but C++ is Microsoft-typical(although itīs not from Microsoft).

    klausi
    When I close my eyes nobody can see me...

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    88
    Stoustrup (sorry if I misspelled him) wrote once that C++ binaries should have the same size as C binaries! and I agree with him.

    but most compiler are not really good! they include the C-Library in C++ binaries -> so the C++ binaries get bigger

    the gcc itself is really great, it generates one of the smalles C code possible, but the g++ ist IMHO ****!

    One problem on windows systems is, that the C-Runtime Library can be dynamically linked (msvcrt.dll) but the C++ Runtime Library must be linked statically

    @quzah:
    what about the 'header' example?
    header files normally do not increase the binary size!! (only if you link libraries with #pragma)
    Hope you don't mind my bad english, I'm Austrian!

  12. #12
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    Building your application without debugging symbols can really shrink the size of your executable. If executable size is important to you, give it a shot.
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Replies: 11
    Last Post: 03-25-2003, 05:13 PM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM