如果用户类型time_t
定义为__darwin_time_t
,在MacOS X中它本身定义为long
,为什么会出现下面的代码输出8 时间是(null)
?也许这很愚蠢,但我真的无法理解。
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t time = 0x7FFFFFFFFFFFFFFF;
printf("%lu\n"
"Time is %s\n", sizeof(time_t), ctime(&time));
return 0;
}
最佳答案
时间 0x7FFFFFFFFFFFFFFF 似乎是公元 292,471,210,647 年左右,这无疑会导致 ctime
超过 C99 保证的 26 个字符,因此它返回 NULL 而不是溢出其缓冲区。一般来说,尽量避免发生在莫洛克人与埃洛伊人交战之后的任何日期。
关于ctime 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6035000/