I was reading the reference about PROGMEM data (PROGMEM - Arduino Reference)
and I've found in internet examples using thing like this:
Serial.println(PSTR("this is a test"));
But I've also found this case:
Serial.println(F("this is a test"));
I'm tried both in one program where has ram problems, and found that the second case works better. My question is what is the difference? In which case should I use each one?
I've also seen some places where they uses P() instead of F()
I've found that there is a very usefull sprintf_P() function that can use PSTR() as parameter but if I use F() instead, the compiler reports an error.
Krodal:
Perhaps this will be fixed some day. For now it is a little inconsistant.
Ok, I understand.
But I've found stranges different results when I use F() and PSTR() in Serial.println. In a sketch that uses ethercard for tcp/ip (high memory usage), I had problems of garbage sent to Serial instead of some constant strings. I thought that PSTR was stored on flash, then it can't be modified after uploading the program. Then, I suppose PSTR is copying the string to RAM or something like this. This sould not be problem but I received the garbage... Then I replaced PSTR with F and the problem was solved... but F can only be used in Serial.print and a few places, PSTR works with sprintf, strcmp, etc.
anv:
But I've found stranges different results when I use F() and PSTR() in Serial.println. In a sketch that uses ethercard for tcp/ip (high memory usage), I had problems of garbage sent to Serial instead of some constant strings.