P
Pavel
I am writing software for an embedded application and here is the
question.
GCC would emit data declared like
const char text[] = "abc";
to .rodata (i.e. "read only data") section. I can put this section to
flash memory and that would be OK.
I have a structure with one member of it being
const char** array;
This 'array` holds a number of pointers like 'text` described above.
Suppose the structure name is 'str', than the typical declaration I
use is:
const char* arr[] = {text, text, text};
str s = {..., arr, ...};
Those objects ('arr' and 's') are declared global and GCC places them
in .data section;
But the rub is that sometimes I need to assign elements of 'arr' array
dynamically. I have the following declaration:
char* dyn_arr[5]; /*And the real values are assigned in the
program;*/
str dyn_s = {..., dyn_arr, ...};
When compiling this GCC says
'initialization from incompatible pointer type'
When assigning:
dyn_arr[0] = text;
GCC says: 'assignment discards qualifiers from pointer target type'.
Those things with const are to avoid copying read-only data from flash
memory where whole program is stored to RAM as it is done with .data
section which contains "rw" variables;
I see the following solutions:
1) ignore GCC warnings (I wouldn't like doing that)
2) remove 'const' keyword and place read-only data to separate section
which I would not copy to RAM
Your suggestions?
Thanks,
Pavel
question.
GCC would emit data declared like
const char text[] = "abc";
to .rodata (i.e. "read only data") section. I can put this section to
flash memory and that would be OK.
I have a structure with one member of it being
const char** array;
This 'array` holds a number of pointers like 'text` described above.
Suppose the structure name is 'str', than the typical declaration I
use is:
const char* arr[] = {text, text, text};
str s = {..., arr, ...};
Those objects ('arr' and 's') are declared global and GCC places them
in .data section;
But the rub is that sometimes I need to assign elements of 'arr' array
dynamically. I have the following declaration:
char* dyn_arr[5]; /*And the real values are assigned in the
program;*/
str dyn_s = {..., dyn_arr, ...};
When compiling this GCC says
'initialization from incompatible pointer type'
When assigning:
dyn_arr[0] = text;
GCC says: 'assignment discards qualifiers from pointer target type'.
Those things with const are to avoid copying read-only data from flash
memory where whole program is stored to RAM as it is done with .data
section which contains "rw" variables;
I see the following solutions:
1) ignore GCC warnings (I wouldn't like doing that)
2) remove 'const' keyword and place read-only data to separate section
which I would not copy to RAM
Your suggestions?
Thanks,
Pavel