Suppose I want to implement a "hard reset counter" for none power cycling resets. In order to do so I need a variable that will not get automatically initialized. Without Arduino this is pretty simple. I follow the documentation Memory Sections and thus implement something like
uint8_t reset_counter __attribute__ ((section (".noinit")));
void setup() {
++reset_counter;
}
Of course I know the dangers of not initialized variables and I am aware that this is not reliable at all. However if I compile from the command line then this works as expected. If I use the Arduino Ide though it does not.
If I implement
uint8_t reset_counter __attribute__ ((section (".noinit"))) = 1;
and try to compile from the command line it will lead to an error (as expected). However with the Arduino IDE I can compile it. Thus I suspect that the IDE overwrites the section attribute somehow. Hence the variable ends up in the wrong section and thus gets initialized.
Has anyone a hint how to tell the Arduino IDE to not mess with my declarations?
Udo