Date: Mon, 24 Nov 1997 21:03:10 -0800 (PST) Message-Id: <199711250503.VAA01601@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Anton Helm , djgpp AT delorie DOT com From: Nate Eldredge Subject: Re: strange behavior of difftime() Precedence: bulk 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 double difftime(time_t time1, time_t time0) { return (double)time1 - (double)time0; } --cut-- Nate Eldredge eldredge AT ap DOT net