What are clock_t and time_t?
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:
Code:
#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?
Re: What are clock_t and time_t?
Quote:
what exact datatypes these
They are generally defined as long int.
Re: What are clock_t and time_t?
Quote:
Originally Posted by jamadagni
how many bytes they hold
This you can always find out using sizeof().
Re: What are clock_t and time_t?
Why not find it out yourself by looking into the header file?
Re: What are clock_t and time_t?
Quote:
Originally Posted by bood
Why not find it out yourself by looking into the header file
/usr/include/time.h did not have any useful info.
Re: What are clock_t and time_t?
Quote:
Originally Posted by jamadagni
/usr/include/time.h did not have any useful info.
Pretty weird...
This from my gcc 3.4.3/mingw
Code:
#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
Re: What are clock_t and time_t?
Quote:
Originally Posted by jamadagni
/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:
Code:
/* 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.
Re: What are clock_t and time_t?
__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