Date: Sun, 8 Aug 1999 14:34:08 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Michal Strelec 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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 . 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.