Author: Dieter Buerssner
Date: 14:28:28 05/11/05
Go up one level in this thread
On May 11, 2005 at 12:16:53, Rémi Coulom wrote:
>On May 11, 2005 at 11:14:52, S J J wrote:
>
>>I have not been able to find a C++ command that returns the time.
>>Does anyone know of one?
>>
>>Thanks,
>>Steve
>
>The function is time:
>
>#include <ctime>
>#include <iostream>
>
>int main()
>{
> std::cout << std::time(0) << '\n';
>}
>
>See also:
>http://www.scit.wlv.ac.uk/cgi-bin/mansec?2+time
It might be worth to note, that the above man page overspecifies time() for
Standard C (and C++ I assume). In Standard C tome does not need to return
seconds, even less seconds since 1970. There are other functions in the Standard
C library to calculate seconds differences of to time_t values, or calendar
dates. time_t might not be an integral type (although it is for implementations
I know). I guess in Standard C there is no good way to printf() time_t values
portably. Of course, one normally won't want to do that either, and time
differences are enough to know.
As you can see below, time() could even always return time_t(-1). In practice,
it will return something better ...
time_t can be any arithmetic type, it does not have to be an integral type. It
could be double.
Unfortunately, in the context of chess engines, time() will in general not be
sufficient, because the resolution is not defined. The normal resolution of 1
second will not be enough for fast games. So one has to use less portable
functions like GetTickCount() on Windows or gettimeofday() with Unix. In
practice, this is no big problem, because the details can easily be hidden in a
system specific module.
Regards,
Dieter
7.23.2.4 The time function
Synopsis
#include <time.h>
time_t time(time_t *timer);
Description
The time function determines the current calendar time. The encoding of the
value is unspecified.
Returns
The time function returns the implementation’s best approximation to the current
calendar time. The value (time_t)-1 is returned if the calendar time is not
available.
If timer is not a null pointer, the return value is also assigned to the object
it points to.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.