Is it possible to place string to progmem w/o using an array ?
I tried const PROGMEM char *const ptr = "NUMBER1";
I tried const PROGMEM char *const ptr PROGMEM = "NUMBER1";
I tried const PROGMEM char *const ptr PROGMEM = (PGM_P)"NUMBER1";
but no luck , pointer in flash, string in sram. should be some c++ tricks. may be reinterpret cast, may be something else, but
I Do Not Believe That This Is Impossible
PS: I know how to store in PROGMEM an array of chars
About half-way down the page is a method that creates a structure composed of a character array, then puts the strings into progmem using the structure, but that requires that all strings be the same length.
The other method is to create the strings as character arrays in progmem, then create an array of pointers to the character arrays in progmem.
If you only have a single string, instead of an array of strings, it should be a bit easier.
septillion, nothing wrong with an array , just want to know if it possible w/o array . but this const char* const one PROGMEM = "NUMBER1"; place string to sram.
david_2018, I know how to put array to progmem , question about how to put string w/o array. Nick uses array to store string
Yes , my string formally, looks like in your example. and question how to put and string also to progmem , but with one line w/o declare an array in PROGMEM
may be
const char *const ptr PROGMEM = (some magic attribute here)"NUMBER1";
but for this need to know c++ as an expert
@alexblade: You're trying to solve a problem that doesn't exist. A "string" (aka c-string) IS AN ARRAY (with a null termination at the end). Just use the array notation and get on with things!!!
this is not "invented problem", simple I not well know c++. if language doesnt allow to us in the same line mark/declare the string as progmem-string then , yes I will use an array , as additional row of code to declare string in progmem
I understand that will be strlen_P + 2. but this question not about speed/capacity/optimization. I didnt say that need/better to use pointer instead array. I just want figure out about possibility c++
alexblade:
this is not "invented problem", simple I not well know c++. if language doesnt allow to us in the same line mark/declare the string as progmem-string then , yes I will use an array , as additional row of code to declare string in progmem
according to C++11 specification, C++ doesn't have syntax to mark a string literal with 'attributes'.
only functions and variables can have 'attributes' .
PROGMEM is attribute((progmem))
the progmem attribute is used by AVR specific linker script to move the variable to dedicated section of the final hex or binary. the build tools don't understand the attribute, only pass it over
Im not "getting" into expert. too hard for me sorry.
yes I thought may be exist some alternative, but I understand - no. sorry and thank you for your time