Re: check if a variable is time_t

Eric Sosman <Eric.Sosman@xxxxxxx> writes:

Pietro Cerutti wrote On 06/26/07 15:34,:
Eric Sosman wrote:
You've got a (potentially) worse problem, though. If
the computer on the other side of the network is not the
same kind as yours or is running a different O/S, its time_t
representation may be different from yours. Even if both
are POSIX systems that count seconds since the Epoch, you
still need to take care of endianness -- of representation
issues in general. You would be *much* better off using a
text format for over-the-network exchanges between what
might be dissimilar machines. You don't need to go all the
way through strftime on output and strptime on input; even
a digit string representing a plain seconds count would
avoid a good deal of trouble.

What about using htonl and ntohl on the value before sending /
after receiving it?

You could do that, if you assume time_t is 32 bits
on both systems. If you encounter a machine where time_t
is 64 bits (one suggested cure for "the 2038 bug"), you'll
still have trouble.

Most 64-bit systems have a 64-bit time_t, and they're getting quite
common these days.

Måns Rullgård

Relevant Pages