this post was submitted on 15 Jun 2023
7 points (100.0% liked)
Programming
13358 readers
20 users here now
All things programming and coding related. Subcommunity of Technology.
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Using
clock()
solely for delta values is absolutely a valid approach, as stated. The issue is thatclock_t
may not be large enough of some systems to safely keep you from an overflow, especially with arbitrary values. Additionally, some systems will include the time children processes were alive in subsequentclock()
calls, furthering possible confusion. These are reasons why I would avoidclock()
in favor oftime()
, even though your concerns are absolutely valid.At the end of the day you have to determine which style of unpredictability you want to work around. Dealing with the
times()
,clock()
, andclock_gettime()
class of functions opens you up to managing what the kernel considers time passed, and what is accumulated vs what is not. While usingtime()
can have shifts in time according to upstream NTP servers, as well as daylight savings time.I would also make the argument that if an NTP server is adjusting your time, it is most likely more accurate than what your internal clock (CMOS or otherwise) was counting, and is worth following.