PDA

View Full Version : What are clock_t and time_t?



jamadagni
7th January 2006, 12: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?

munna
7th January 2006, 14:46
what exact datatypes these

They are generally defined as long int.

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

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

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

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

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


#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif

#ifndef _TIME_T_DEFINED
typedef long time_t;
#define _TIME_T_DEFINED
#endif


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

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


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

That tells me exactly how time_t is defined.

fullmetalcoder
12th January 2006, 16: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" .
;)

edit:

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