Libraries

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dear freaks,
I am working on a project the last month and I have finally completed it. The resulting code was about 10K
and the ram used was almost 33% of the atmega16 which I chose.

Somewhere in the code I use numbers of "double" precision (ex. -1.02389234) and the function "dtostrf" to show the result to a LCD screen.
During some debugging I read the manual page for "dtostrf" and I found that I should link with "libm.a".
So I did, and wow!!!
My code decreased at about 8K and ram usage at 8.4%!!!

I need someone to explain me why this happens and what exactly are these libraries for. Why are they needed if you already have done the correct "#includes" ?

Thank you very much for your time and help.

P.S. I use AVR Studio 4.16 build 638 with WinAVR-20090313.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the search function of the forum. This has been discussed an hundred times.

Gist: Linking against libm.a makes things better. Not using double or floating point is much more clever.

Stealing Proteus doesn't make you an engineer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Why are they needed if you already have done the correct "#includes" ?

For starters you need to understand the difference between including source text when compiling (actually before compiling, see below), and linking in (parts of) a binary library when linking.

A #include just reads in a text file, which (normally) contains function headers, #defines etc. This is handled by the compiler pre-processor. It is a plain text replacement, done before the compiler proper goes to work parsing the source and producing machine code out of it.

An include file does not contain any pointer to the machine code implementing functions it has headers for. That machine code resides in other object files (the files that the compiler produces) or in a library (several object files glued together).

Thus, the same header file can be used for describing different version of (pre-)compiled functions in different libraries (as long as they adhere to the function prototypes in the header file. So you can have the same, or similar, libraries implemented more or less clever. You just changed from a library that was less clever for the AVR, to one that was more clever.

All above are implifications, of-course, but better than nothing..

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much for your answers.