On Thu, Jan 08, 2004 at 10:04:26PM +0100, Chris Liechti wrote:

> uhm, if you implement functions that you dont use, isnt a library what 
> you want?
> 
> you can create a library and the linker will only take the functions 
> that are used. see msp430-libc for hints how to build a library.

Lib's have a disadvantage, you can not change preprocessor directives. 
Let me explain with a small example. I have a module and use some portpins.
The portpins are defined by
#define A 0x01
#define B 0x02
#define C 0x04
 in one project. In another project I use
#define A 0x80
#define B 0x40
#define C 0x20
 A, B, C are constants for the compiler and saves much code and execution time.
With libs I can do this only using variables, and the code is bigger.
Imagine you have a loop count (constant for a project), and in some projects
it is 0 - the compiler would eliminate your code to nothing (using #define).
With a lib I have to set the loop count using a variable. At compile time
the compiler does not know how often the loop is called and implement the
whole loop - also for counts of 0. Another example are switch/case, and -
I am sure - there are much more improvements possible.

Because of the limited ressources of uControllers this was always important
for me, so libs are only useful in some cases.

        Matthias

Reply via email to