我在libcurl中找到了如下代码:
const char *
curl_easy_strerror(CURLcode error)
{
switch(error) {
case CURLE_OK:
return "No error";
case CURLE_UNSUPPORTED_PROTOCOL:
return "Unsupported protocol";
.....
}
Run Code Online (Sandbox Code Playgroud)
据我所知,如果要返回指针,则需要确保指针所指向的内存不会被更改或释放。为什么此libcurl代码有效?