about time and time_t

G

Guest

Hello everyone,


In MSDN for time function,

time_t time(
time_t *timer
);

http://msdn2.microsoft.com/en-us/library/1f4c8f33(VS.80).aspx

the return value of time is time_t, but in the Return Value section, it
mentioned,

Return the time as seconds elapsed since midnight, January 1, 1970. There is
no error return.

So, I am wondering whether time_t could be represented as elapsed number of
seconds correctly and safely -- no data lost if we convert return value to
unsigned long?

Like,

unsigned long second = time (NULL);


thanks in advance,
George
 
D

David Lowndes

In MSDN for time function,
time_t time(
time_t *timer
);

http://msdn2.microsoft.com/en-us/library/1f4c8f33(VS.80).aspx

the return value of time is time_t, but in the Return Value section, it
mentioned,

Return the time as seconds elapsed since midnight, January 1, 1970. There is
no error return.

So, I am wondering whether time_t could be represented as elapsed number of
seconds correctly and safely -- no data lost if we convert return value to
unsigned long?

George,

time_t is (in later compilers) defined as a 64-bit value (with the
option of being a 32-bit value for backward compatibility). It's best
if you play by the rules and use it with appropriate functions such as
difftime.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top