The type of time_t (was: struct tm -> time_t converter wanted)

Alan J Rosenthal flaps at dgp.toronto.edu
Sat Oct 29 04:46:34 AEST 1988


roland at wheaties.ai.mit.edu (Roland McGrath) writes:
>With the Epoch defined as it is for Unix (Jan 1 00:00:00, 1970), it is
>desirable to have a signed `time_t' type.  Although I didn't, the world
>did exist before 1970.

First of all, negative time_t values don't mean time before time zero.  This is
confirmed by the return value (time_t)(-1) from mktime() which means "not a
time I can represent", rather than 31 Dec 1969 23:59:59 GMT.

Most of all, time_t is for representing events that happen while the system is
running:  the current time, the scheduled time of events in the future
(e.g. alarms, sleeps), and the time of events in the past (e.g. file
timestamps).  It is not sufficient, nor should it be, for representing the
times of all events in human history and future; a more sophisticated, and
larger, representation is required for that.  So any zero-date in the past
is ok, because a file need not be able to have a timestamp predating the
writing of the operating system it is available on.

ajr

--
#define __STDC__ 0



More information about the Comp.std.c mailing list