Re: ctime double double check



Flash Gordon <spam@xxxxxxxxxxxxxxxxxx> writes:
aisling.cronin@xxxxxxxxx wrote, On 08/03/07 15:37:
<snip>

Thank you all for pointing out all my coding errors, I have fixed it
up, hopefully this is correct
#include <time.h>
#include <stdio.h>
int main (void)
{
time_t Timestamp;
char *CTime;
Timestamp= 1144412677847 ;
CTime=ctime(&Timestamp);
printf ("The Time is %s ", CTime);
}
I am not sure of what to cast the timestamp as I get ..
test.c:8: warning: integer constant is too large for "long" type

Then perhaps the compiler knows it does not fit it to a long and it
thought you should know? It might fit in to an unsigned long.

1144412677847 is between 2**40 and 2**41. If it doesn't fit into a
long, it's not likely to fit into an unsigned long.

To the OP: where did you get the number 1144412677847, and what makes
you think it's a valid time_t value?

As others have pointed out, the standard imposes very few requirements
on how time_t is represented. (In my opinion, it's under-specified.)
There happens to be a very common system-specific representation,
where a time_t is an integer type (usually signed, usually 32 bits,
sometimes 64 bits) representing the number of seconds since 1970-01-01
00:00:00 GMT. Assuming that particular representation, the value
1144412677847 represents a time in late December of the year 38,234.
(It may or may not be coincidental that if you divide it by 1000, it
represents a time about 13 months ago.)

Any program that works with specific numeric time_t values is
non-portable, perhaps needlessly so. If you really need to work with
the specific representation I described above, you should ask in a
system-specific newsgroup, perhaps comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: ctime double double check
    ... Timestamp= 1144412677847; ... printf ("The Time is %s ", CTime); ... It might fit in to an unsigned long. ... There happens to be a very common system-specific representation, ...
    (comp.lang.c)
  • Re: ctime double double check
    ... Timestamp= 1144412677847; ... printf ("The Time is %s ", CTime); ... It might fit in to an unsigned long. ...
    (comp.lang.c)
  • Re: ctime double double check
    ... Timestamp= 1144412677847; ... Get a different compiler. ... The argument to ctime() must be a `time_t*', ... of arguments and returns an `int' value. ...
    (comp.lang.c)
  • Re: [SLE] cron not recognizing changes to /etc/cron.d files [SOLVED]
    ... What we are looking for is an easy method to set it to some arbitrary timestamp, in the past or in the future. ... The ctime of the file cited above is the time when the jobs in /etc/cron.daily are run. ... For that, they need to change the ctime of that file, let's say to 04:45 or something like that. ...
    (SuSE)
  • Re: ctime double double check
    ... time_t CTime; ... Timestamp= 1144412677847; ... A proper compiler is required to complain about this abuse. ... I am not sure of what to cast the timestamp as I get .. ...
    (comp.lang.c)