Go Down

Topic: Memory and unused functions in a library (Read 257 times) previous topic - next topic

eddiea6987

well not exactly a library just another c file and header file , ive yet to learn about libraries and linking so for now i am only writing things in separate c and h files
but i wonder if i write a generic c file with multiple functions for doing a lot of tasks but  i only use some of them in my main c file do the unused ones take up memory?


I could print the Arduino logo on a box of cereal and sell it as "Arduin-O's"

Arrch

The compiler is smart enough to get rid of unused code. Of course, you could always write small example and test it yourself.

Erdin

Sometimes a class or variable or interrupt routine is still in the compiled file, even when it is not used.

I use defines to disable blocks of code.

Code: [Select]

// Select which one to use

// #define ENABLE_I2C
// #define ENABLE_BLINKING_LED
#define ENABLE_TEMPERATURE

...

#ifdef ENABLE_TEMPERATURE
  // do someting with the temperature sensor
  float temperature = getTemperature();
  Serial.println( temperature);
#endif

Go Up