I have a module-level character string declared this way:
char* sStatus = NULL;
This string can be NULL (no status) or have some associated string indicating what the status is. The status string can be read and written from different parts of the program, which is fully synchronous, so there are no concurrency issues.
How can I best update this string? For example, if I write something like:
void addNewRecord(){
sStatus = "adding new record";
...
...
sStatus = "finished adding new record";
}
Then it works, but my fear is that the string is local to the function, so once the function exits the string is no longer valid? The program is not crashing however. I printed out the address of the pointer and it is definitely not on the stack and appears to be in some kind of constant area of memory, so it should be safe.
Nevertheless, I am wondering what the proper way is to handle this kind of data structure usage.