
Chris Newman <Chris.Newman@innosoft.com>:
On Mon, 20 Jan 1997, Markus G. Kuhn wrote:
I just wanted to start writing a ISO 8601 subset -> time_t conversion routine, but to my great disappointment I discovered that ISO C does not seem to allow portable conversion of a broken-down time into time_t.
You can do a binary search of the time_t space using the gmtime() function. This does require the assumption that time_t is an integral type, but works well.
There is no reason to assume that time_t is integral, and good reasons to assume it often is not, and more often in the future than at present. The restricted range of 32-bit time_t values is a problem in common applications, and until 64-bit machines are universal the easiest way to sidestep the problem is "typedef double time_t;". In any case, since time is a continuous quantity a floating-point representation makes perfect sense, and ANSI (aware of this) permits it. Nathan Myers ncm@cantrip.org

In message <m0vmqDs-0002ndC@mill>, Nathan Myers wrote:
Chris Newman <Chris.Newman@innosoft.com>:
You can do a binary search of the time_t space using the gmtime() function. This does require the assumption that time_t is an integral type, but works well.
There is no reason to assume that time_t is integral, and good reasons to assume it often is not, and more often in the future than at present.
As the successful student of a numerical analysis course, I had of course considered first to implement a finite difference variant of Newton's algorithm to find a zero crossing for X in the function distance(gmtime(X), my_brocken_down_time). This is very fast and might work most of the time nicely with both integer and fp time_t. But then I stepped back and saw that self-learning API usage code like this is certainly pretty cool, but it is ridiculously bad software engineering practice. I would never want to find code like this in so-called portable software that I am supposed to port, and I'd probably fire a programmer who implements a hack like this for me. My code will contain a simple conversion routine that assumes POSIX.1 and can easily be replaced by whatever else your non-POSIX system uses. Markus p.s.: I fixed already the static buffer bug in the last posted version. -- Markus G. Kuhn, Computer Science grad student, Purdue University, Indiana, USA -- email: kuhn@cs.purdue.edu
participants (2)
-
kuhn@cs.purdue.edu
-
ncm@cantrip.org