Passing PROGMEM into a function that takes const char*
Posted: Wed Aug 09, 2017 8:23 pm
I've been trying to clear up some space in RAM by putting all my String literals into PROGMEM.
For functions that take const __FlashStringHelper* I can use the F() macro to create a __FlashStringHelper* from PROGMEM.
For example Serial extends the Print class and it's println method is overloaded to accept __FlashStringHelper*
However I'm not sure what to do when a function requires a const char* as a parameter.
For example the printf function doesn't accept __FlashStringHelper*
The following code fails to compile.
What's the best way to pass data from PROGMEM to a function that requires const char* ?
There are many other functions out there that don't have any idea about __FlashStringHelper, so it would be nice to have an easy macro that could make this work.
For functions that take const __FlashStringHelper* I can use the F() macro to create a __FlashStringHelper* from PROGMEM.
For example Serial extends the Print class and it's println method is overloaded to accept __FlashStringHelper*
Code: Select all
Serial.println(F("My String Text goes here"));
However I'm not sure what to do when a function requires a const char* as a parameter.
For example the printf function doesn't accept __FlashStringHelper*
The following code fails to compile.
Code: Select all
Serial.printf(F("My name is: %s"), name);
What's the best way to pass data from PROGMEM to a function that requires const char* ?
There are many other functions out there that don't have any idea about __FlashStringHelper, so it would be nice to have an easy macro that could make this work.