Mail Archives: djgpp/1997/11/25/00:05:26
At 12:07 11/25/1997 +0100, Anton Helm wrote:
[snipped]
>>From the above quote I would assume that there is no restriction on time0
and time1,
>especially the standard doesn't assume that time1 > time0.
>
>Why does difftime() from the DJGPP library produce erronous results if
time0 > time1 ??????
>
>difftime() should return a negative result, but actually it returns
>
>(double)(UINT_MAX - d)
>
>where d is the absolute value of the difference of time0 and time1.
Probably because `time_t' is an unsigned integer type. An integer
subtraction is done, and the result is less than zero. But due to the
workings of two's complement arithmetic, when considered as an unsigned
value, this will be a very large number. IMHO, this is not really a problem,
since most people know which way time goes. :) But if you want a fix, here's
a replacement `difftime.c' which should do the job (the patch was larger
than the new file)
--cut--
#include <time.h>
double
difftime(time_t time1, time_t time0)
{
return (double)time1 - (double)time0;
}
--cut--
Nate Eldredge
eldredge AT ap DOT net
- Raw text -