Currently I'm writing C++ code on Arduino. In an example, I find a expression
Serial.print(F("Disconnected from central:"));
It's obvious that this statement is used to send string to the serial, but why it uses F(string) instead of using string directly?
I try to google it but with no results. If someone know it, I would be greatly appreciated.
This macro is Arduino-specific, it's not "C++" as such.
It places the string in flash memory, to conserve RAM.
It means the string cannot be modified when the program runs.
One current definition is:
#define F(slit) (reinterpret_cast<const __FlashStringHelper *>(PSTR(slit)))
See the source code for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With