Why is the difference between two time_ts returned by the difftime( time_t t1, time_t t2) method as a double? I don’t see where the precision requirement comes from.
Why is the difference between two time_t s returned by the difftime( time_t t1,
Share
Because
time_tis simply defined in the standard as anarithmetic type capable of representing times.That’s about all it says about it. It doesn’t have to be an integer, it doesn’t have to represent seconds. It could only ever be a multiple of ten or it may be a floating point type capable of representing times down to a resolution of 10-43 seconds.
The quote from
C99 7.23.1 Components of timeis (slightly paraphrased):Hence people who blindly work out the time difference with:
may find that their code doesn’t work on all platforms.
Now I don’t know off the top of my head any platforms where it’s not a simple seconds since the epoch but I’ve been bitten by assumptions like this before, such as assuming
AthroughZare contiguous whereas, in fact, that is not required and doesn’t work so well on the mainframe products which use EBCDIC. And, yes, they’re still in heavy use despite apparently having been dying since the ’60s 🙂The C99 rationale document has this to say: