www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/08/11:52:07

Date: Sun, 8 Aug 1999 14:34:08 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Michal Strelec <strelec AT adam DOT osu DOT cz>
cc: djgpp AT delorie DOT com
Subject: Re: CLOCKS_PER_SEC in DJGPP
In-Reply-To: <7oe8d8$unv$1@ns.felk.cvut.cz>
Message-ID: <Pine.SUN.3.91.990808143351.23423k-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Fri, 6 Aug 1999, Michal Strelec wrote:

> But how many ticks timer do in a seconds in real?

Use the macro CLOCKS_PER_SEC defined by <time.h>.  ANSI C Standard
says you shouldn't assume anything about the value of this macro.

> And in DjGpp Timer.h I also found
> #define CLOCKS_PER_SEC 91
> In BC31 timer.h
> #define CLOCKS_PER_SEC 18.2
> 
> So I'm a quit confused and I don't know how many times per sec timer runs.

This isn't an issue of the timer frequency (DJGPP doesn't change the
basic 18.2-times-per-second clock frequency), this is an issue of the
implementation of the `clock' library function.  Unlike Borland, DJGPP
doesn't force your code into floating-point computations whenever you
use CLOCKS_PER_SEC.  By defining an integer value for CLOCKS_PER_SEC,
your programs can still use integer code that is usually quite a bit
faster.  To make it work, the actual timer counter was scaled up by
the factor of 5 (18.2 * 5 = 91).  Thus the value you see in time.h.

> On i386 the maximum allowed type of variable is ulong, isn't it?
> But function clock returns long. So maximum number is 2147483647L. If I
> transfer it to days (using 18.2 ticks per sec ) I get 1365 day = 3.7 year
> (aproximately). But may program may run more then 3.7 year (in one run)
> counter of this type may overflow.

Note that the DJGPP version will overflow after about 273 days, due to
the scaling by 5.

Programs that run for such a long time should use `gettimeofday' or
similar functions once a day to reset the seconds' count and maintain
the seconds only per day or so.  If you need to compute time
differences in seconds, use `mktime' and `difftime' functions.

- Raw text -


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