delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/24/18:09:08

Message-Id: <3.0.5.32.19971125000726.00979ea0@hal.nt.tuwien.ac.at>
Date: Tue, 25 Nov 1997 00:07:26 +0100
To: djgpp AT delorie DOT com
From: Anton Helm <tony AT nt DOT tuwien DOT ac DOT at>
Subject: strange behavior of difftime()
Mime-Version: 1.0

Quote from the ANSI C Standard *):

7.12.2.2 The difftime function

Synopsis
        #include <time.h>
        double difftime(time_t time1, time_t time0);


Description
   The difftime function computes the difference between two calendar times time1 -
time0.

Returns
   The difftime function returns the difference expressed in seconds as a double.


End quote.



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.

E.g. you get a positive difference of about 128 years if you set time1 to 1990 and time0 to 1997.



*) ISO/IEC 9899:1990 p.171

**************************************************************
Dipl.-Ing. Anton HELM   *T*  mailto:tony AT nt DOT tuwien DOT ac DOT at
Institut fuer           *U*  http://www.nt.tuwien.ac.at/~tony/
Nachrichtentechnik und  *W*  http://www.nt.tuwien.ac.at/
Hochfrequenztechnik     *I*  talkto:tony AT eagle DOT nt DOT tuwien DOT ac DOT at
Guszhausstr. 25/389     *E*  phoneto:+43-1-58801-3520
A-1040 Wien, AUSTRIA    *N*  faxto:+43-1-5870583
**************************************************************

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019