I'm having SRAM overflow problems with my 8bit atmega328p in my Arduino Uno, which has 2KB of SRAM, so I'm defining all my for loops with bytes as counters instead of ints. As in:
for(byte i=0;i<16;i++) buf[i]=(char)ap1[i];
Would it make any difference if I declared the integer literal 16 as a constant?
const byte BUFSIZE=16;
Or using the preprocessor:
#define BUFSIZE 16
There's also the macro PROGMEM
which stores variables in flash memory, which I've decided to use for all my constants, but is it not the point of const to do this? as well as aiding the compiler in warning you if you screwed up changing the variable.
const byte BUFSIZE PROGMEM=16;
AFAIK, using const would save BUFSIZE in the flash memory, but how about using the preprocessor? Using the preprocesor would be the exact the same as using the literal 16, as far as i'm concerned.
This fear arose from the fact that string literals are saved in Flash and then transferred to SRAM, wasting twice the space, which you can solve using the arduino macro F("thisisastring"), which stores them in flash memory, and I don't want to waste 2 bytes of SRAM in every for loop I use