arduino – Whats the meaning of F(string) in C++?

arduino – Whats the meaning of F(string) in C++?

This macro is Arduino-specific, its 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.

F() is one of the most powerful functions, which was added with the 1.0 release of the IDE. I keep mixing the terms macro and function. F() really isn’t a function, it is a #define macro which lives in WString.h

#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

It is a macro, which use for storing strings in flash memory rather than RAM.

arduino – Whats the meaning of F(string) in C++?

Leave a Reply

Your email address will not be published. Required fields are marked *