Go Down

Topic: String Literals (Read 950 times) previous topic - next topic

plbyrd

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?

Example:

if(a == "STRING LITERAL")

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.

Delta_G

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.

AWOL

1 RAM
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