I have a library file (pinChange.h) that contains:
#if !defined NUM_PCINTS
#define NUM_PCINTS 20
#endif
and I include it thus:
#define NUM_PCINTS 3
#include <pinChange.h>
as I'm trying to override the value of NUM_PCINTS (to reduce the size of an array - int x[NUM_PCINTS] for efficiency)
when I use Serial.print(NUM_PCINTS) I get two different values: 3 if I print it from the calling sketch and 20 if I call it from the library....looks like I'm getting a "cached" version of the library linked in. If I modify the library, to set NUM_PCINTS to - say - 15 then I get the new value 15 shown from the library call, but still 3 from the call in the sketch
What I DONT want to do is have something like:
pinChange pcInstance(NUM_PCINTS);
or
pcInstance.begin(NUM_PCINTS);
and dynamically allocate the array in the library at runtime, as the extra code required will doubtless outweigh the savings I make! (and of course dynamic allocation=danger of dangling pointers, fragmented heaps, random bugs balh blah blah)
I just want the library user to be able to (easily) override the value used by the library...this method obviously doesn't work - is there a way that will? How do I force the library to recompile , or always prefer the previously #defined value?