Thread: Making executables slim.

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    47

    Question Making executables slim.

    Hello,

    i've compiled the following code with BCC55.

    Code:
    #include <iostream.h>
    
    int main (int argc, char *argv[])
    {
     cout<<"Yo!";
     return(0);
    }
    This Yo proggie has 110KB, how i can compile
    to get smaller exe's.

    Regards,
    Robert

  2. #2
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    I have never used Borland before but with VC++ you can choose between a Debug or Release compile. If you can do that with Borland then choose Release and that will cut down the file size.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  3. #3
    Sayeh
    Guest
    The executable (also called on object file) is this large because you are using C++. C++ includes signfigant amounts of unnecessary code in compilations. This is one of the reasons why C++ programs are slower and bulkier.

    This is not a fault of C++ itself, it's a fault of all C++ compilers.

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    That's the diff between Release and Debug? How do you make a Release version? I've always just gone with the default Debug when you compile.

    --Garfield
    1978 Silver Anniversary Corvette

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    There is a great deal of difference betwen a release and a debug complie. Also, not all "basic" versions of the current compilers will optimize - that could be your problem.

    Sayeh:

    No. A modern C++ compiler will optimize code to, at least, as good as a C compiler. The compiler writers know well where the "++ bloat" comes from and do not create object that uses, for example, VFT's. A professional version C++ compiler will produce, (when correctly directed), as slim an .EXE as any C complier with the same source.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    A professional version C++ compiler will produce, (when correctly directed), as slim an .EXE as any C complier with the same source.
    They should generate more or less the same code from the same source, providing the C++ is valid C. However, when using the templatised version of the iostream library (or any template libraries), most compilers seem to generate bloated code due to the way in which they handle templates.
    zen

  7. #7
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> Also, not all "basic" versions of the current compilers will optimize - that could be your problem. <<

    I'm on MSVC++6. Shouldn't that be able to make Release? How do you do it? Thanks..
    1978 Silver Anniversary Corvette

  8. #8
    Registered User The15th's Avatar
    Join Date
    Aug 2001
    Posts
    125
    Garfield;

    build -> config's -> release. then it should compile all your files to the release folder, not the debug.
    arrh, i got nothing good to say.
    http://www.praxis1.vic.edu.au/home/dcola/

  9. #9
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Thanks! So you do this when you are done with the program?
    1978 Silver Anniversary Corvette

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    zen:
    >>> most compilers seem to generate bloated code due to the way in which they handle templates

    Yes, that's true, but if he replaced his cout with a printf then the fact that it is a "++" compiler should not make any difference.

    Garfield:
    >>> Thanks! So you do this when you are done with the program?

    Yes. When compiling for debug, the compiler switches off optimization, and adds some extra code to the .EXE to help you debug. When you are happy with your code, you compile a release version which will be smaller and usually faster.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    >> Yes, that's true, but if he replaced his cout with a printf then the fact that it is a "++" compiler should not make any difference. <<

    No, it shouldn't. It all depends on the libraries that are included. Otherwise, it is fine. There are some subtle differences that you can do with C and not C++. C++ hides a little. For instance, memory allocation. C is a little more flexible that C++.
    1978 Silver Anniversary Corvette

  12. #12
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    There are some subtle differences that you can do with C and not C++. C++ hides a little. For instance, memory allocation. C is a little more flexible that C++.
    For example?

  13. #13
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    For example the following code:
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        char *p = malloc(1024);
        if(p)
        {
            strcpy(p, "Hello World.");
            printf("%s\n", p);
            free(p);
        }
        return 0;
    }
    is perfectly legal in C, but under C++ you'll get a diagnostic message because of the conversion of malloc's void * return to char *.
    1978 Silver Anniversary Corvette

  14. #14
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    >>is perfectly legal in C, but under C++ you'll get a diagnostic message because of the conversion of malloc's void * return to char *.

    As far as I understand there's a good reason for that. I could only see myself using malloc() in c++ if I didnt know what type of variable I was providing space on the free store for (new and delete are far better and do things like calling constructors and destructors which are essential). How often this would be I dont know, but I doubt it would be good if I found myself in such a position.

    Anyway, c++ gives use of newer cast operators like static_cast<T> to try help coders better cope with C style casts which are often a source of error

  15. #15
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    is perfectly legal in C, but under C++ you'll get a diagnostic message because of the conversion of malloc's void * return to char *.
    Yes, but this will have no affect on the code produced by the compiler. It's for compile time checking only.
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 07:00 AM
  2. making self contained executables?
    By m37h0d in forum C++ Programming
    Replies: 18
    Last Post: 03-30-2008, 06:27 PM
  3. Small executables in VC++ 8
    By Bleech in forum Windows Programming
    Replies: 3
    Last Post: 06-20-2007, 08:28 AM
  4. STL + MSVC++ = big executables ?
    By teneniel in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2002, 02:12 PM
  5. About Unix Programming - Making a career desision
    By null in forum C Programming
    Replies: 0
    Last Post: 10-14-2001, 07:37 AM