Since you marked this question with the C++ tag (and not the C tag), I'd suggest you to just use std::string
as return value:
std::string returnErrorString(int errorCode)
{
switch(errorCode)
...
return "This error code means that...";
}
(Unless e.g. this is a pure-C interface function exported by some DLL that you want to make usable from different versions of VC++ compilers. In this case you can't have STL classes at the boundaries. But in this case you must clearly state in the documentation that the returned const char *
string must not be deleted by the caller code.)
In modern C++, unless there is a strong requirement for high-performance in some tight loop, just use a robust convenient string class like std::string
instead of C-like const char*
.