time_t
this is platform dependent type. I found difftime
which returns difference in seconds, but I did not find function for simple subtraction without any convertations. How I know standard does not does not guarantee that will go consistently throughout the whole time continuum and does not told anything about encoding of time_t
. Also it does not told that two different time_t
will not represent one time moment. But I'm not sure about this in real life.
The time_t datatype is a data type in the ISO C library defined for storing system time values. Such values are returned from the standard time() library function. This type is a typedef defined in the standard header. ISO C defines time_t as an arithmetic type, but does not specify any particular type, range, resolution, or encoding for it. Also unspecified are the meanings of arithmetic operations applied to time values.
Unix and POSIX-compliant systems implement time_t as an integer or real-floating type (typically a 32- or 64-bit integer) which represents the number of seconds since the start of the Unix epoch: midnight UTC of January 1, 1970 (not counting leap seconds). Some systems correctly handle negative time values, while others do not. Systems using a signed 32-bit time_t type are susceptible to the Year 2038 problem.]
https://en.wikipedia.org/w/index.php?title=Time_t&oldid=450752800
I meant I need time_t
in return:
time_t v1;
time_t v2;
time_t diff;
diff = some_substract_fct(v2, v1)
Is it safe to compare/substract two time_t
without difftime
? E.g.:
time_t v1;
time_t v2;
time_t diff;
if (v2 > v1)
{
....
}
if (v2 == v1)
{
....
}
v3 = v2-v1;
instead
if (difftime(v2, v1) > 0)
{
}
if (difftime(v2, v1) == 0.0)
{
}
diff = some_substract_fct(v2, v1)