Include some function form library

This is a discussion on Include some function form library within the C Programming forums, part of the General Programming Boards category; Hi how can I include some function from library? for example from String.h I need only strcmp() how can I ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4

    Unhappy Include some function form library

    Hi
    how can I include some function from library?
    for example from String.h
    I need only strcmp()

    how can I do it

    second question is this way can reduce exe file size?

    thank you

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Write your own.


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

  3. #3
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    If you're statically linking, the compiler will generally only pull in what you use.

    If you're dynamically linking, the whole .dll / .so has to be there, so it doesn't make a damn bit of difference.

    How big is your program? For most things, code is measured in kilobytes, and you're only going to get minimal savings. It's a bit worse on Windows (programs tend to be bigger, mostly due to DLL hell). If you really want to squeeze out space, I'd recommend upx, for Windows executables. For *nix, I've never found a need. There are some compiler optimizations for space, but I'd say that speed is much more important. (upx doesn't affect the running speed of a program, only loading time - which you might win back for just doing less disk I/O.)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4
    I really appreciate your help
    I use the code in Microcontroller and flash memory is out of space
    I think the most suitable solution is to write my own function that I know how it work

    thank you again for you help

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Assuming your linker works like usual linkers, it is very unlikely that you will gain anything from writing your own strcpy/strcmp or similar functions. For one thing, strcmp for example would only be about a dozen instructions at the most[1] - so it's not like you would be able to get rid of MUCH code that way.

    The linker should only add functions that are ACTUALLY called into the executable.

    Aside from trying some "optimize for size" options that you can feed the compiler, the other option is to find common chunks of code and turning that into functions.

    Also, if you are using a mix of different functions that overlap in functionality, you may want to consider converting to using only ONE form. For example, if you use itoa() to convert an integer to a string, and you also use sprintf() somewhere else, then using sprintf() will remove the need to use itoa(), and if you don't use a function, it won't be included in the final binary [again, assuming the linker works like most linkers do].

    Analyzing the map-file generated by the linker may also show which functions are big - these would be a target to work at for making them smaller.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 10-29-2006, 04:04 AM
  2. Header file include order
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 05-17-2006, 03:22 PM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 08:10 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21