I usually return std::string
from a function because returning const char*
requires that the calling server issue an output memory buffer, and this buffer does not change.
But returns const char*
valid if it is from a string literal?
const char* generate_c_string() {
return "ABC";
}
Executing in this way (if it really is) will most likely be faster, since I will not need to dynamically allocate memory for the build std::string
.
It is probably valid because it is const char* x = "ABC";
valid. Is there a link to the C ++ standard confirming its reliability?
source
share