在Arduino C+中,我希望在使用32位签名的time_t类型时避免2038年的溢出问题,因此我想专门使用Teensy中的Time.h (或者TimeLib.h;我在Arduino 1.8.7上为Teensy 3.5编写代码)。
但是IDE似乎忽略了Teensy的Time.h,其中time_t被定义为:
typedef unsigned long time_t;我发现,无论我包含什么,我使用的time_t类型都被编译为"long int“。这段代码显示:
time_t t = "ABC";编译器将显示time_t实际上定义为long int。
invalid conversion from 'const char*' to 'time_t {aka long int}' [-fpermissive]我甚至尝试将Teensy的时间文件夹(https://github.com/PaulStoffregen/Time)复制到我的草图文件夹中,但是没有效果:
#include "Time\TimeLib.h"如何确保在Arduino中使用未签名的32位time_t?另外,当我调用now()时,返回未签名的long time_t的是Teensy的now(),而不是内置的long int time_t
提前感谢!
发布于 2019-06-03 13:32:31
在teensy TimeLib.h中,定义为:
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef unsigned long time_t;
#endifsys/_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所以这不是个谜,它被忽略了。否则,由于类型冲突,您将无法编译。
https://stackoverflow.com/questions/56426827
复制相似问题