C++ 蒂恩西';s#包括<;TimeLib.h>;被Arduino压倒了

C++ 蒂恩西';s#包括<;TimeLib.h>;被Arduino压倒了,c++,arduino,time.h,time-t,teensy,C++,Arduino,Time.h,Time T,Teensy,在Arduino C+中,我希望在使用32位、带符号的time\u t类型时避免2038年的溢出问题,因此我想特别使用Teensy的time.h(或者说TimeLib.h;我正在Arduino 1.8.7上为Teensy 3.5编写代码) 但是IDE似乎忽略了Teensy的Time.h,其中Time\u t的定义为: typedef unsigned long time_t; #if !defined(__time_t_defined) // avoid conflict with newli

在Arduino C+中,我希望在使用32位、带符号的time\u t类型时避免2038年的溢出问题,因此我想特别使用Teensy的time.h(或者说TimeLib.h;我正在Arduino 1.8.7上为Teensy 3.5编写代码)

但是IDE似乎忽略了Teensy的Time.h,其中Time\u t的定义为:

typedef unsigned long time_t;
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef unsigned long time_t;
#endif
我发现无论我包含什么,我使用的时间类型都被编译为“long int”。该代码显示:

time_t t = "ABC";
编译器将显示时间t实际上被定义为长int

invalid conversion from 'const char*' to 'time_t {aka long int}' [-fpermissive]
我甚至尝试将Teensy的时间文件夹()复制到我的草图文件夹中,但没有成功:

#include "Time\TimeLib.h"
如何确保在Arduino中使用未签名的32位时间? 另外,我希望在调用now()时,是Teensy的now()返回未签名的longtime\u t,而不是内置的long inttime\u t


提前谢谢

在teensy TimeLib.h中定义为:

typedef unsigned long time_t;
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef unsigned long time_t;
#endif
sys/\u types.h
将其定义为:

#define _TIME_T_    long        /* time() */
typedef _TIME_T_    __time_t;
在以下几个地方使用:

#if !defined(__time_t_defined) && !defined(_TIME_T_DECLARED)
typedef _TIME_T_    time_t;
#define __time_t_defined
#define _TIME_T_DECLARED
#endif

所以这不是一个谜,它被忽略了。否则,由于类型冲突,您将无法编译。

谢谢,现在我可以看得更清楚了。是否有方法覆盖sys/_types.h中的定义?@Dave取决于用法。如果您想使用TimeLib,最好将time\u t更改为utime\u t或其他类似的东西。或者将其隐藏到单独的命名空间中