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().
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.
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
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.