Page 1 of 1

esp_timer_get_time return type

Posted: Fri Aug 24, 2018 2:18 pm
by michprev
Hi,
What is the reason why https://esp-idf.readthedocs.io/en/lates ... _get_timev returns int64_t instead of uint64_t?

Re: esp_timer_get_time return type

Posted: Fri Aug 24, 2018 4:27 pm
by loboris
Uinx time representation for dates before Thursday, 1 January 1970 are negative, for example
-1000000 -> Sat, 20 Dec 1969 10:13:20 GMT

Re: esp_timer_get_time return type

Posted: Fri Aug 24, 2018 4:36 pm
by ESP_igrr
The reason was that the return type represents a moment in time, relative to some point (startup). So time can be both positive and negative, even if this function only ever returns positive values. This is similar to time_t being signed on most systems even though time() always returns positive values, unless one has a time machine. With a 64-bit type, loss of one bit of range would not matter in practice, plus arithmetic with signed types is less error prone.

Re: esp_timer_get_time return type

Posted: Fri Aug 24, 2018 5:03 pm
by michprev
I should have looked at commit message, thank you!