Hi there,
I am looking for an elegant way to store text in program memory.
This text shall then be copied to a buffer, for manipulating, and displayig on LCD.
So far I have come up with
strcpy_P (buffer, reinterpret_cast<const char*> (F("text stored in progmem")));
This works.
The F() macro takes care of storing in program memory.
However the strcpy_P likes a data type of const char, hence the reinterpret cast.
Strcpy_P is like strcpy, exept it accepts data coming from progmem.
To be honest, I don't understand completely what I am doing here.
For example, I thought I could use strcpy instead of strcpy_P, and then re-cast the data to char*
instead of const char*.
However the compiler then complains:
error: reinterpret_cast from type 'const __FlashStringHelper*' to type 'char*' casts away qualifiers
I understand I'm casting away the const qualifier, but that is exactly what I intend. For which reason does the compiler not allow this?
I'm also a bit afraid of using reinterpret_cast. Is this safe in the above context?
Thanks
Thomas