Mail Archives: djgpp/1999/08/08/11:52:07
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 -