Go Down

Topic: client.println(F("")) (Read 633 times) previous topic - next topic

gc9n

Apr 02, 2013, 01:09 am Last Edit: Apr 02, 2013, 01:11 am by gc9n Reason: 1
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: [Select]
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: [Select]
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'

Delta_G

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. 

gc9n


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

liudr

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.

PaulS

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.

Go Up