Question about using PROGMEM and strstr

I've got a question regarding the use of PROGMEM with other functions like strstr().

I have several instances of strings stored in SRAM that I'd like to move over to flash using PROGMEM. The strings are used along with the function strstr().

Here is the original code:

const char *pleaseCall = "Please Call";

strstr(rxBuffer,pleaseCall);

and here are my changes:

const char *pleaseCall PROGMEM = "Please Call";

strstr(rxBuffer,pleaseCall);

now I've also seen reference to using this code instead:

const char *pleaseCall PROGMEM = "Please Call";

strstr_P(rxBuffer,pleaseCall);

Both cases compile with no errors however the code using strstr_P() increases the code size by 52 bytes. Unfortunately I don't have my Arduino on hand so I can't upload the code to test. So my question is which case should I use or is there another way of doing this? Thx.

wayneft:
Both cases compile with no errors however the code using strstr_P() increases the code size by 52 bytes. Unfortunately I don't have my Arduino on hand so I can't upload the code to test. So my question is which case should I use or is there another way of doing this? Thx.

It would be nice if the compiler kept track of which pointers point to FLASH and which point to RAM. Then it could give a compile-time error when you passed a FLASH address to a function expecting a RAM address. But it doesn't. The compiler relies on the programmer knowing that FLASH addresses and RAM addresses have to be processed by different functions.

johnwasser:

wayneft:
Both cases compile with no errors however the code using strstr_P() increases the code size by 52 bytes. Unfortunately I don't have my Arduino on hand so I can't upload the code to test. So my question is which case should I use or is there another way of doing this? Thx.

It would be nice if the compiler kept track of which pointers point to FLASH and which point to RAM. Then it could give a compile-time error when you passed a FLASH address to a function expecting a RAM address. But it doesn't. The compiler relies on the programmer knowing that FLASH addresses and RAM addresses have to be processed by different functions.

Can I assume that I need to use the strstr_P() and not strstr() then?
...and doing a little more research what is the difference between strstr_P and strstr_PF

wayneft:
Can I assume that I need to use the strstr_P() and not strstr() then?

Yup

wayneft:
what is the difference between strstr_P and strstr_PF

"Far pointers for memory access >64K"
http://www.nongnu.org/avr-libc/user-manual/group__avr__inttypes.html

Thanks for the help. I have a follow up question too

Do I need to do anything special when passing a PROGMEM pointer to a function? In other words will this work:

const char *pleaseCall PROGMEM = "Please Call";

function1(pleaseCall);

void function1(const char * _pC){
  strstr_P(rxBuffer,_pC);
}

I think that works. Just try it and you'll know for sure.

I prefer to follow the avr-libc convention and use PGM_P for the param type and add a _P to the name. Just to try to keep from accidentally mis-calling it.

Thanks. I'll give it a try when I get home tonight.