简体   繁体   中英

Creating a const char* from another const char*

i am working on an embedded medical device and have a little problem. I have 2 seperated "application groups", which menas that both of them a strictly separated but nevertheless need to communicate. Group A is the safe area and Group B the unsafe Group which cant do anything in the group A. Now my problem:

In Group A i created a array of struct which holds some informations about syringes.

struct SyringeData{
    int cylinderFloorArea;
    int innerDiameter;
    int outerDiameter;
    int zeroPoint;
    const char* syringename;
    int volume;
    bool activate;
    bool selectSize;
};

In Group B i need the const char* syringename. The communication between both groups is realized about a shared memory area. Group B has a method to build an menu using a framework called LVGL. There i need the following:

static const char* map[] __attribute__((section(".guiMem_data"))) = {"xxx", "\n", "yyy","\n", "zzz", "\n", "xyz", ""};

After filtering the array of struct from the shared memory area i maybe just need a few of them to put them into the map array i listed above. How can i get some of the shared array of struct syringenames to the map, because both are const char* and i can't modify them after init. If i am right i have to initialize const char* at the beginning This map array has to be changed during runtime again and again

Thank you

static const char* map[] creates a read/writable array of pointers to read-only memory (strings). It will get allocated in RAM on all mainstream systems. You can modify it at any time like any other array.

Simply do: map[i] = something; , where something is a string allocated elsewhere. If you don't store a pointer to what map[i] previously pointed at, that data is now lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM