Timekeeping in ANSI C

Rahul Dhesi dhesi at bsu-cs.UUCP
Thu Feb 11 13:25:37 AEST 1988


In article <594 at acornrc.UUCP> rbbb at acornrc.UUCP (David Chase) describes a
structure that holds a time value and continues:
>This structure can encode dates from 1900 AD to something like 47000 AD.

Sooner than you can say "UNIX is a Trademark of ...", 47000 AD will be
here.  The greatest mistake a designer can make is to assume that a
certain date and time will never come.  Such short-sightedness has
caused problems over and over again, yet we see it again and again.
Just recently we heard about chaos in the DEC-20 world because they had
to extend their time structure and use up some reserved fields that
people had already begun to use for other things.

The right way to do it is as follows:

     typedef struct {
        long hi_time;
        long lo_time;
        time_t *next_val;
     } time_t;

the next_val field will be NULL until 47000 AD, at which time the
routine returning the time value will malloc() space for another struct
to hold the higher 64 bits.  Then, another epoch later, the time_t
structure will become a linked list of three structs, and so on, to the
end of time (or end of free memory).

The only problem I can see with the above typedef is that it won't
compile because of the forward reference.  But at least it will be
valid far longer than anything that compiles that has been proposed so
far.
-- 
Rahul Dhesi         UUCP:  <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi



More information about the Comp.lang.c mailing list