In Arduino C+, I wanted to avoid the year 2038 overflow problem when using 32-bit, signed time_t type, so that I'd like to specifically use the Time.h from Teensy (Or TimeLib.h for that matter; I am writing code for Teensy 3.5 on Arduino 1.8.7).
But the IDE seems to ignore Teensy's Time.h, in which time_t is defined as:
typedef unsigned long time_t;
I find out that no matter what I include, the time_t type I am using is compiled as "long int". This code reveals that:
time_t t = "ABC";
The compiler will show that time_t is actually defined somewhere as long int:
invalid conversion from 'const char*' to 'time_t {aka long int}' [-fpermissive]
I even tried copying the Teensy's Time folder (https://github.com/PaulStoffregen/Time) to my sketch folder, and do this to no avail:
#include "Time\TimeLib.h"
How to make sure that I am using an unsigned, 32-bit time_t in Arduino? Also I want when I call now() it's Teensy's now() that returns unsigned long time_t, not the built-in long int time_t
Thanks in advance!
In teensy TimeLib.h it's defined as:
#if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc
typedef unsigned long time_t;
#endif
and the sys/_types.h
defines it as:
#define _TIME_T_ long /* time() */
typedef _TIME_T_ __time_t;
Used in several places as:
#if !defined(__time_t_defined) && !defined(_TIME_T_DECLARED)
typedef _TIME_T_ time_t;
#define __time_t_defined
#define _TIME_T_DECLARED
#endif
So it's not such a mystery it's ignored. Otherwise you wouldn't be able to compile because of conflicting types.