Thread: include and program size

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    8

    include and program size

    Hello,

    I wish to make my .exe as small as possible.
    When I load an header file with include, for example #include math.h, does the compiler compile and include inside the exe all the functions of math.h, even those not used ?

    If this is the case, it should be better tor extract the needed function manually to copy them in the source .c , isn't it ?

    All the best

    Pierre

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Header files contain only definitions, so you can include them whether you really need them or not. The only downside is increased compilation time, and later confusion wondering why you included them in the first place.

    As for the size of the executable, that's really down to the quality of the libraries involved. You may only use sin() inside your code, but you can't really control whether cos() and tan() make it into the executable. That depends on how well your libary was created in the first place.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    8
    Hello Salem

    Thank you for the fast answer.

    >"As for the size of the executable, that's really down to the quality of
    the libraries involved. You may only use sin() inside your code, but you can't really control whether cos() and tan() make it into the executable. That depends on how well your libary was created in the first place."

    Sorry if this sound naive, it's very new for me :
    If I want to make my own header file, Is there something I have to put to tell the compiler not to load unused functions ?

    All the best

    Pierre

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Quote Originally Posted by PierreB
    If I want to make my own header file, Is there something I have to put to tell the compiler not to load unused functions ?
    No. Good compilers will only load the functions necessary from the libraries referenced.

    Another way is to compress the exe file itself using a program such as upx.exe
    Last edited by WaltP; 04-01-2004 at 03:39 AM.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Adventures in labyrinth generation.
    By guesst in forum Game Programming
    Replies: 8
    Last Post: 10-12-2008, 01:30 PM
  3. Trouble with DMA Segmentation Faults
    By firestorm717 in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 09:20 PM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM