ctime返回null [英] ctime returning null

查看:216
本文介绍了ctime返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果将用户类型time_t定义为__darwin_time_t,而在MacOS X中将其本身定义为long,为什么以下代码输出8 Time is (null)?也许这很愚蠢,但我无法真正理解它.

If the user type time_t is defined as __darwin_time_t, which itself is defined as long in MacOS X, why does the following code outputs 8 Time is (null)? Maybe it's something silly, but I can't really understand it.

#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而不是而不是溢出其缓冲区.通常,请尽量避免在莫洛克人与伊洛伊人开战之后发生的任何事情.

Time 0x7FFFFFFFFFFFFFFF appears to be around the year 292,471,210,647 AD, which undoubtedly causes ctime to exceed the 26 characters it is guaranteed by C99, so it returns NULL rather than overflowing its buffer. In general, try to avoid any dates that occur after the Morlocks go to war with the Eloi.

这篇关于ctime返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆