C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-22-2009, 07:14 PM   #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
thepolo is offline   Reply With Quote
Old 05-22-2009, 07:20 PM   #2
+++ OK NO CARRIER
 
quzah's Avatar
 
Join Date: Oct 2001
Posts: 10,262
Write your own.


Quzah.
__________________
Hundreds of thousands of dipshits can't be wrong.


Are you up for the suck?
quzah is offline   Reply With Quote
Old 05-22-2009, 08:59 PM   #3
int x = *((int *) NULL);
 
Cactus_Hugger's Avatar
 
Join Date: Jul 2003
Location: Banks of the River Styx
Posts: 891
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)
Cactus_Hugger is offline   Reply With Quote
Old 05-24-2009, 03:44 PM   #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
thepolo is offline   Reply With Quote
Old 05-24-2009, 05:11 PM   #5
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Reply

Tags
library, reduce

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a circulating mouse pointer to use a Potentionmeter phoenix23 C Programming 16 10-29-2006 05:04 AM
Header file include order cunnus88 C++ Programming 6 05-17-2006 03:22 PM
Bisection Method function value at root incorrect mr_glass C Programming 3 11-10-2005 09:10 AM
Please Help - Problem with Compilers toonlover C++ Programming 5 07-23-2005 10:03 AM
qt help Unregistered Linux Programming 1 04-20-2002 09:51 AM


All times are GMT -6. The time now is 09:14 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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