View Full Version : What are clock_t and time_t?

7th January 2006, 11:38
In the description of time.h I have read that clock_t and time_t are arithmetic types representing times, but I do not understand what exact datatypes these are - how many bytes they hold, etc. For instance, if I have:

#include <time.h>
time_t now;
now = time();
what formatting would I need to use if I use the variable now in a printf statement?

7th January 2006, 13:46
what exact datatypes these

They are generally defined as long int.

7th January 2006, 14:15
how many bytes they hold
This you can always find out using sizeof().

7th January 2006, 14:53
Why not find it out yourself by looking into the header file?

7th January 2006, 15:27
Why not find it out yourself by looking into the header file/usr/include/time.h did not have any useful info.

8th January 2006, 01:53
/usr/include/time.h did not have any useful info.

Pretty weird...
This from my gcc 3.4.3/mingw

typedef long clock_t;

typedef long time_t;

And it seems from the standard that it's implemention dependent

11th January 2006, 16:00
/usr/include/time.h did not have any useful info.
mmm... Here is what the time.h header included with MSVC++ 6.0 has:

/* Define the implementation defined time type */
#ifdef _WIN64
typedef __int64 time_t; /* time value */
typedef _W64 long time_t; /* time value */
#define _TIME_T_DEFINED /* avoid multiple def's of time_t */

That tells me exactly how time_t is defined.

12th January 2006, 15:47
__int64 is obviously a 64bit (implicitly signed) integer which in pure C++ (i.e. : not polluted by Microsoft) is called a "long long int" .


to learn more about _W64 check out the files included by your time.h