On Fri, Aug 29, 2008 at 5:13 PM, ammar azif <[EMAIL PROTECTED]> wrote: > I wrote a python program that used time() function from the time module to > retrieve time in seconds since Epoch. After the value was retrieved which I > checked is a float by using type(), the value was then written into a file > in binary format. Then another C program that I wrote opened the file and > converted the value into a time_t variable but it was totally different from > the correct value. Then I found that the time_t size is actually 4 byte > integer which is not the same with 8-byte float value returned by > time.time(). Why is this so? Being written with C library, isn't python > suppose to work well with it?
The C time_t type is very loosely specified; in ANSI C it is only required to be an arithmetic type. According to Wikipedia (http://en.wikipedia.org/wiki/Time_t), Posix-compliant systems still have latitude to implement it as 32 or 64 bits. Python tries to be bit higher level, giving you fractional seconds if the implementation supports it and a common data type across implementations. So there is not an exact match in functionality. If you want to write data to file in a format that can be read by another program, you should look at the struct module. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor