esp_timer_get_time return type

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

esp_timer_get_time return type

Postby michprev » Fri Aug 24, 2018 2:18 pm

Hi,
What is the reason why https://esp-idf.readthedocs.io/en/lates ... _get_timev returns int64_t instead of uint64_t?

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: esp_timer_get_time return type

Postby loboris » Fri Aug 24, 2018 4:27 pm

Uinx time representation for dates before Thursday, 1 January 1970 are negative, for example
-1000000 -> Sat, 20 Dec 1969 10:13:20 GMT

ESP_igrr
Posts: 1653
Joined: Tue Dec 01, 2015 8:37 am

Re: esp_timer_get_time return type

Postby ESP_igrr » Fri Aug 24, 2018 4:36 pm

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.

michprev
Posts: 92
Joined: Fri Aug 04, 2017 8:57 pm

Re: esp_timer_get_time return type

Postby michprev » Fri Aug 24, 2018 5:03 pm

I should have looked at commit message, thank you!

Who is online

Users browsing this forum: No registered users and 23 guests