如果malloc
分配失败,我们应该再试一次吗?
在这样的事情:
char* mystrdup(const char *s)
{
char *ab = NULL;
while(ab == NULL) {
ab=(char*)malloc(strlen(s)+1);
}
strcpy(ab, s);
return ab;
}
Run Code Online (Sandbox Code Playgroud)
while循环对检查内存分配有效吗?