I have a legacy code snippet that looks like:
const char *GetStr() const {
return ("");
}
I am wondering whether this is a risky code as instead of returning a global character pointer, returning a local string literal? For example, perhaps, the following code snippet is better.
const char *NullStr = "";
const char *GetStr() const {
return NullStr; // instead of ""
}
What could be pros/cons?
Even the following implementation could be better:
const char *GetStr() const {
static const char * lNullStr = "";
return lNullStr;
}