gpt4 book ai didi

c++ - 是否有平台不将 std::time_t 表示为 unix 时间?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:48:32 26 4
gpt4 key购买 nike

来自 http://www.cplusplus.com/reference/ctime/time_t :

time_t

Alias of a fundamental arithmetic type capable of representing times, as those returned by function time.

For historical reasons, it is generally implemented as an integral value representing the number of seconds elapsed since 00:00 hours, Jan 1, 1970 UTC (i.e., a unix timestamp). Although libraries may implement this type using alternative time representations.

Portable programs should not use values of this type directly, but always rely on calls to elements of the standard library to translate them to portable types.

有人知道 std::time_t 不表示为 unix 时间的此类实现示例吗?

最佳答案

根据 §17.6.4.3.4/1:

For each type T from the Standard C library,184 the types ::T and std::T are reserved to the implementation and, when defined, ::T shall be identical to std::T.

184 ... time_t ...

因此,time_tstd::time_t 都是实现定义的类型。提示在某种程度上是正确的。

POSIX 兼容系统尝试将其实现为 unix 时间,但 POSIX 并非基于 C++ 标准,反之亦然。也许将来会在特定的嵌入式系统中创建一个 C++ 编译器,它具有不同的 time_t...

关于c++ - 是否有平台不将 std::time_t 表示为 unix 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19892137/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com