In an ISR I want to keep things quick. At the same time I want to limit variable scope. Storage space is not a factor.
I have this line:
const char trigs = "aAbBcCdDeEfFgGhHiIjJ";
When this is global, the resulting compile stats show:
Sketch uses 3418 bytes (10%) of program storage space. Global variables use 431 bytes (21%) of dynamic memory.
When it's inside the function (to limit scope) I get:
Sketch uses 3470 bytes (10%) of program storage space. Global variables use 431 bytes (21%) of dynamic memory.
The extra program space is 52 bytes, which is more than the size of the variables, so there must be extra code in there. That might be something to do with initialization checks... but why? Isn't a
const already known? If there's a difference in where it's stored, why doesn't global variable space change?
If I prefix this as
static const I'm back to the first behavior
(3418 / 431).
So the immediate answer is just to use
static const, I suppose. But I'm still curious what's going on. Can someone elucidate?