Go Down

Topic: String Literals (Read 1 time) previous topic - next topic


OK, I've read the documentation on the F() function and using the PROGMEM modifier.  I have some questions now (which I'm sure have been previously answered but I did not find them readily via searches here).

1) Are string literals in code stored in SRAM or referenced from flash?



Is "STRING LITERAL" in SRAM or program space?  I have tried if(a == F("STRING LITERAL")) and get compile errors because the result of F("STRING LITERAL") is obviously not char*.

2) What is the correct way for testing equality of a string against a string stored with F()? 

3) What happens to the memory used by pulling a value with pgm_read_word (etc)?  Are the return values of these functions newly allocated memory in SRAM?  Are they register variables that go away on their own?  Will using this technique result in memory leaks over time? 

With so little RAM available I want to make sure I understand the ramifications of each of these things.


That's not how you would compare two strings whether one is in progmem or not.  There you are testing a for equality with a pointer to that string literal.  Maybe strcmp is what you need.
Ad hoc, ad loc, and quid pro quo.  So little time - so much to know!  ~Jeremy Hillary Boob Ph.D


2 strcmp_p
3 no memory leaks unless you program it badly
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131