Help with C++ <ctime>

B

B Williams

I have been searching the internet trying to find the definition for the
function time() in the standard library header <ctime>. Can someone help me
with this? Thanks in advance.
 
A

Alan Johnson

B said:
I have been searching the internet trying to find the definition for the
function time() in the standard library header <ctime>. Can someone help me
with this? Thanks in advance.

std::clock_t std::time(std::clock_t * tloc) ;

Returns the number of seconds since the Epoch (midnight, Jan 1, 1970).
If tloc is not NULL, it also writes the same value to the location
provided by the parameter.
 
B

B Williams

Alan Johnson said:
std::clock_t std::time(std::clock_t * tloc) ;

Returns the number of seconds since the Epoch (midnight, Jan 1, 1970). If
tloc is not NULL, it also writes the same value to the location provided
by the parameter.
Thanks Alan,
I really appreciate it.
 
D

Default User

B said:
I have been searching the internet trying to find the definition for
the function time() in the standard library header <ctime>. Can
someone help me with this? Thanks in advance.


What do you mean by "definition"?




Brian
 
J

Jack Klein

std::clock_t std::time(std::clock_t * tloc) ;

Returns the number of seconds since the Epoch (midnight, Jan 1, 1970).
If tloc is not NULL, it also writes the same value to the location
provided by the parameter.

time() returns type time_t.

clock() returns type clock_t.
 
D

Default User

Alan said:
std::clock_t std::time(std::clock_t * tloc) ;

Returns the number of seconds since the Epoch (midnight, Jan 1,
1970). If tloc is not NULL, it also writes the same value to the
location provided by the parameter.

As Jack mentioned, this is the wrong declaration. You are also
incorrect in the semantics. There's no requirement that time() return
seconds, certainly not seconds since the epoch. That happens to be
common, but portable should not rely on that or need that.



Brian
 
S

sonison.james

You can locate the ctime header file using "locate" or "find" commands
on UNIX

Thanks and regards
SJ
 
R

Ron Natalie

Default said:
As Jack mentioned, this is the wrong declaration. You are also
incorrect in the semantics. There's no requirement that time() return
seconds, certainly not seconds since the epoch. That happens to be
common, but portable should not rely on that or need that.
Correct, time_t's encoding is not specified. All you can do is
pass it to otherf unctions. If you want to know elapsed time
from some point, use difftime().
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top