在处理相同的错误时多次调用errno
是否安全?或者使用本地副本更安全?是否连续调用errno来避免?
此示例说明我的问题:
// If recvfrom() fails it returns -1 and sets errno to indicate the error.
int res = recvfrom(...);
if (res < 0)
{
// Risky?
printf("Error code: %d. Error message: %s\n", errno, strerror(errno));
// Safer alternative?
int errorNumber = errno;
printf("Error code: %d. Error message: %s\n", errorNumber, strerror(errorNumber));
}
+1有趣的问题证明有一个不平凡的答案和可能的实际后果。 – 2010-10-06 08:39:36