I'm working on an app that has strings in an array like:
static char * strings[] = {
"ABC DEF",
"EF",
"GHI"
};
Note, that the type doesn't have const modifier!
In my app I loop over the array and revert the strings. The expected result is:
{
"FED CBA",
"FE",
"IHG"
}
However the result I get is:
{
"FED CAB",
"AB",
"IHG"
}
The reason for this is because in the original array the strings are compiled to overlap: strings[1] overlaps the end of strings[0]!!!
// When I printed out the pointers it turned out that in the RAM
// it stored my strings "overlapping":
// 00 01 02 03 04 05 06 07 08 09 0a 0b
// "A B C __ D E F \0 G H I \0"
static char * strings[] = {
0x00, 0x05, 0x08
};
Is there any way (besides not having the const modifier which doesn't work) to tell the compiler not to overlap my strings? Is this a bug in the compiler or in my code? What workaround can I do?