time_t, arithmetic types, difftime, and -

B

Beej Jorgensen

That got me thinking:

time_t is an arithmetic type, and so the '-' operator will work on it.

But difftime() exists because there's nothing in the Standard that
specifies the encoding of a time_t variable, so this might BE true:

(t1 - t0) != difftime(t1, t0)

is this line of thinking correct?

Is this was the Rationale means when it says, "No arithmetic properties
of [clock_t and time_t] are defined by the Standard", that is, "When you
difftime() time 7 from time 10, you might not get time 3, even though
you will get 3 when you use the '-' operator."

-Beej
 
J

jameskuyper

Beej said:
That got me thinking:

time_t is an arithmetic type, and so the '-' operator will work on it.

But difftime() exists because there's nothing in the Standard that
specifies the encoding of a time_t variable, so this might BE true:

(t1 - t0) != difftime(t1, t0)

is this line of thinking correct?

Yes. For instance, the time_t value corresponding to
2009-06-11T21:11:02Z might be 20090611.211102; the value for
2009-06-11T21:10:59Z might be 20090611.211059. difftime(t1, t0) must
return 3.0, but t1-t0 would be 0.000043.
Is this was the Rationale means when it says, "No arithmetic properties
of [clock_t and time_t] are defined by the Standard", that is, "When you
difftime() time 7 from time 10, you might not get time 3, even though
you will get 3 when you use the '-' operator."

Yes. The manner in which time_t values are encoded is completely
unspecified by the standard. Emphasize the word "completely". Think
about it.
 
F

Fred

Beej said:
That got me thinking:
time_t is an arithmetic type, and so the '-' operator will work on it.
But difftime() exists because there's nothing in the Standard that
specifies the encoding of a time_t variable, so this might BE true:
  (t1 - t0) != difftime(t1, t0)
is this line of thinking correct?

Yes. For instance, the time_t value corresponding to
2009-06-11T21:11:02Z might be 20090611.211102; the value for
2009-06-11T21:10:59Z might be 20090611.211059. difftime(t1, t0) must
return 3.0, but t1-t0 would be 0.000043.
Is this was the Rationale means when it says, "No arithmetic properties
of [clock_t and time_t] are defined by the Standard", that is, "When you
difftime() time 7 from time 10, you might not get time 3, even though
you will get 3 when you use the '-' operator."

Yes. The manner in which time_t values are encoded is completely
unspecified by the standard. Emphasize the word "completely".  Think
about it.

Even if you know the encoding, you cannot rely on your own
subtractions to get the correct delta time.

A correct implementation of difftime must also know about all of
the leap-seconds that have been added between the two input times
in order to correctly determine the difference.

For example, the last three leap-seconda were added on:
Jun 30 1998,
Jan 31 2005, and
Jan 31 2008

It is possible that the leap-second will be abolished in the
future, which will cause UTC to begin drifting from solar time.
 
E

Eric Sosman

Jack said:
Eric said:
[...]
Bits 0-5: Seconds (0-60)
Bits 6-11: Minutes (0-59)
Bits 12-16: Hours (0-23)
Bits 17-21: Day of month (1-31)
Bits 22-25: Month (1-12)
Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
[...]
Assuming that we correct for Eric's use of 33 bits,

I *might* have made an off-by-one error, but isn't it
*far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
Yes, yes, *of course* that's the explanation ...

Trivia question: Why 1957 for Year Zero?
 
L

Lew Pitcher

Jack said:
Eric Sosman wrote:
[...] [snip]
Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
[...]
Assuming that we correct for Eric's use of 33 bits,

I *might* have made an off-by-one error, but isn't it
*far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
Yes, yes, *of course* that's the explanation ...

Trivia question: Why 1957 for Year Zero?

Guesses:
1) The year of the passing of John von Neumann,
2) The year of the founding of Digital Equipment Corporation, or
3) The year of the founding of the Advanced Projects Research Agency of
the US Department of Defense


--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
B

Beej Jorgensen

Lew Pitcher said:
On June 12, 2009 09:39, in comp.lang.c, Eric Sosman

Guesses:
1) The year of the passing of John von Neumann,
2) The year of the founding of Digital Equipment Corporation, or
3) The year of the founding of the Advanced Projects Research Agency of
the US Department of Defense

No, no! It was the year the first Frisbee flying disc was produced!
Yes!

A legitimate guess: birth year of FORTRAN?

-Beej
 
L

Lew Pitcher

No, no! It was the year the first Frisbee flying disc was produced!
Yes!

A legitimate guess: birth year of FORTRAN?

And I counter with
the year that the first "recursive stack" (aka lifo) was implemented in a
computer language
or
the year that the Athena computer was completed
or
the year that the first all-solid-state computer (the NCR 304) was built

But, I think your FORTRAN guess is closer to the money

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
E

Eric Sosman

Lew said:
Jack said:
Eric Sosman wrote:
[...] [snip]
Bits 26-32: Year minus 1957 (0-127, i.e., 1957-2084)
[...]
Assuming that we correct for Eric's use of 33 bits,
I *might* have made an off-by-one error, but isn't it
*far* more likely that CHAR_BIT == 11, sizeof(int) == 3?
Yes, yes, *of course* that's the explanation ...

Trivia question: Why 1957 for Year Zero?

Guesses:
1) The year of the passing of John von Neumann,
2) The year of the founding of Digital Equipment Corporation, or
3) The year of the founding of the Advanced Projects Research Agency of
the US Department of Defense

As with all such, there are many candidates. (3) was
closest to the one I had in mind, because even though ARPA
was founded in 1958 rather than 1957, it was in reaction to
the 1957 event. Without the scare Sputnik gave the States,
and the concomitant flow of funding to fight off fear, we
might still be using 4MHz machines with half-megabyte memories.

There was a piece in The Register recently about the first
"portable computer:" No, not the Osborne or some such, but the
on-board navigational system of the Minuteman I, something of
a triumph of miniaturization at the time. According to the
article, the U.S. military was for a time the world's largest
purchaser of those newfangled integrated circuits, and the
principal reason for IC makers to go into and stay in business.
 
R

Richard Bos

Beej Jorgensen said:
No, no! It was the year the first Frisbee flying disc was produced!
Yes!

A legitimate guess: birth year of FORTRAN?

Birth year of a certain Mr. E. Sosman?

Richard
 
S

Steve Allen

A correct implementation of difftime must also know about all of
theleap-secondsthat have been added between the two input times
in order to correctly determine the difference.

a correct implementation of difftime must make a policy decision
of the sort that federal governments around the world have not
been able to make in a consistent fashion: to decide what kind of
seconds are supposed to be counted. See
http://www.ucolick.org/~sla/leapsecs/epochtime.html
for a javascript example of the issues.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top