Pages: [1]   Go Down
Author Topic: client.println(F(""))  (Read 548 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Stupid question but i will ask...

is there any way that i can use the client.println(F("")) with a variable

For example i have this
Code:
client.print(F("Disable Storm(0) , Storm with Thunders(1) , Storm without Thunders(2): <input  type='text' size='1' onkeyup='if(!manualthundereos(this.value)) this.value=\"0\";' name='ST8'  value='"));  
client.print(manualledvalues[8]);
client.println(F("'/> "));

can i do it some how to save SRAM like this..   (second line)
Code:
client.print(F("Disable Storm(0) , Storm with Thunders(1) , Storm without Thunders(2): <input  type='text' size='1' onkeyup='if(!manualthundereos(this.value)) this.value=\"0\";' name='ST8'  value='"));  
client.print(F(manualledvalues[8]));
client.println(F("'/> "));

i get the error: initializer fails to determine size of '__c'
« Last Edit: April 01, 2013, 06:11:28 pm by gc9n » Logged

Offline Offline
God Member
*****
Karma: 17
Posts: 721
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The F macro puts things into flash memory.  When things are in flash memory you can't change them at runtime.  Therefore, it makes no sense at all to use the F macro with a variable even if  you could.  If you can never change it, then why would you have it in a variable? 

Also, since the variable is already in the SRAM, it wouldn't save you anything to use the F macro even if it did work like that. 
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 141
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The F macro puts things into flash memory.  When things are in flash memory you can't change them at runtime.  Therefore, it makes no sense at all to use the F macro with a variable even if  you could.  If you can never change it, then why would you have it in a variable?  

Also, since the variable is already in the SRAM, it wouldn't save you anything to use the F macro even if it did work like that.  

ok i understand. its like executing a text query in SQL server
I Just finish the Sketch and trying to save memory
Thanks..
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use F to print the constant strings and followed by regular print for SRAM variables.  Caution: F doesn't optimize duplicates so if you F the same content in different parts of the program you are duplicating them in FLASH, not exactly efficient. Recommend losing F and learn PROGMEM.
Logged


Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The F macro puts things into flash memory.
No. Everything is in flash memory. The F() macro prevents the compiler from generating code to move the literal strings to SRAM at run time. Thus saving SRAM for other uses.

Variables MUST be defined in SRAM, so not generating code to move the data to SRAM at run time doesn't make sense. Otherwise, they are not variables; they are constants.
Logged

Pages: [1]   Go Up
Jump to: