编译符合 Y2038 的旧 C 代码仍会产生 4 字节变量
根据这个概述,为了编译符合Y2038的旧代码,我们只需要添加预处理器宏 __USE_TIME_BITS64
到 gcc
,但这似乎不适用于 Debian 12 的 ARMv7 主板(书虫):
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
struct stat sb;
printf("sizeof time_t: %zu\n", sizeof(time_t));
printf("sizeof stat timestamp: %zu\n", sizeof(sb.st_atime));
return 0;
}
time_t 仍然是 4 个字节:
root@debian:~# gcc -D__USE_TIME_BITS64 time.c -o time
root@debian:~# ./time
sizeof time_t: 4
sizeof stat timestamp: 4
root@debian:~#
glibc 是 2.33,我在这里做错了什么?
According to this overview in order to compile Y2038 conform old code, we just need to add the preprocessor macro __USE_TIME_BITS64
to gcc
, but that does not seem to work on an ARMv7 board with Debian 12 (bookworm):
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
int main(void)
{
struct stat sb;
printf("sizeof time_t: %zu\n", sizeof(time_t));
printf("sizeof stat timestamp: %zu\n", sizeof(sb.st_atime));
return 0;
}
time_t is still 4 bytes:
root@debian:~# gcc -D__USE_TIME_BITS64 time.c -o time
root@debian:~# ./time
sizeof time_t: 4
sizeof stat timestamp: 4
root@debian:~#
glibc is 2.33, what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据这篇文章(现在有点旧了,其中的某些部分可能没有更相关):
据推测,这包括将
time_t
设为 64 位。因此,如果您的 glibc 版本完全支持此功能,则看起来您设置了错误的宏。您需要:
-D_TIME_BITS=64
According to this post (which is getting a little old now, and some parts of which are probably no longer relevant):
Presumably, this includes making
time_t
64 bit.So if your version of glibc supports this at all, it looks like you're setting the wrong macro. You want:
-D_TIME_BITS=64