Pages: [1]   Go Down
Author Topic: String Literals  (Read 438 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 651
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1 RAM
2 strcmp_p
3 no memory leaks unless you program it badly
Logged

"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.

Pages: [1]   Go Up
Jump to: