code8825 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Serial.print_P() #997

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

I would like two new functions to be introduced: Serial.print_P() and 
.println_P(). These would be versions of Serial.print()/println() that would 
print strings stored in PROGMEM.

Why?

Since many times (if not even most!) the Serial.print()/println() functions are 
called with immutable strings, this would allow coders to easily save a lot of 
RAM.
There have already been a few similar request, see 
http://arduino.cc/forum/index.php/topic,46713.0.html, for instance. Many 
programmers have written own versions of such functions, see 
http://arduino.cc/forum/index.php/topic,98926.msg744215.html#msg744215.

Would this cause any incompatibilities with previous versions?  If so, how can 
these be mitigated?

Not at all, and actually the implementation would be quite trivial. Some can 
even be found in the above-mentioned forum posts.

Original issue reported on code.google.com by sukkopera on 30 Jul 2012 at 8:22

GoogleCodeExporter commented 9 years ago
You can use the F("string") wrapper macro to store a string in PROGMEM and 
print them from there.  This is mentioned on the Serial.print() documentation 
(http://arduino.cc/en/Serial/Print) but could probably be more prominent.  In 
any case, we preferred (from an API perspective) that solution to introducing 
these new functions.  

Original comment by dmel...@gmail.com on 30 Jul 2012 at 2:24

GoogleCodeExporter commented 9 years ago
That is perfectly fine, unfortunately I hadn't noticed it, sorry.

Although this creates an asymmetry with the other functions that use PROGMEM 
strings (i.e.: strcpy_P(), strcmp_P()), so maybe in the future these should be 
updated to use the F() macro as well.

Anyway thanks, sorry for opening a useless issue.

Original comment by sukkopera on 31 Jul 2012 at 9:08