Author Topic: UNIX rollover - why 2^31 signed and not 2^32 unsigned?  (Read 2344 times)

0 Members and 1 Guest are viewing this topic.

Offline CirclotronTopic starter

  • Super Contributor
  • ***
  • Posts: 3362
  • Country: au
UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« on: May 04, 2022, 11:55:47 pm »
We all know that if nothing is done, UNIX will conk out early 2038 because there are 2^31 seconds from 1 January 1970 till 19th January 2038. My question is - why was a signed integer that has a maximum positive value of 2^31 used as the seconds counter when an unsigned integer value of 2^32 could have been chosen? That would give a counter twice as long. The only reason I can think of is, being signed, it could also deal with negative numbers, that is, dates earlier than 1 January 1970. Does that make any sense at all? Is that how it works?

https://en.wikipedia.org/wiki/Year_2038_problem
 

Offline Someone

  • Super Contributor
  • ***
  • Posts: 5155
  • Country: au
    • send complaints here
 
The following users thanked this post: Circlotron

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 8275
  • Country: ca
    • LinkedIn
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #2 on: May 05, 2022, 01:09:51 am »
I just feel it's sad that those who wanted to create an ultimate OS for everyone would settle on a time format which couldn't even make it to 2050, let alone 2100.  Maybe this short-sight means unix should be dumped?
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4857
  • Country: dk
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #3 on: May 05, 2022, 01:17:13 am »
I just feel it's sad that those who wanted to create an ultimate OS for everyone would settle on a time format which couldn't even make it to 2050, let alone 2100.  Maybe this short-sight means unix should be dumped?

isn't most platforms and timestamps 64bit already?
 

Online BrianHG

  • Super Contributor
  • ***
  • Posts: 8275
  • Country: ca
    • LinkedIn
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #4 on: May 05, 2022, 01:32:37 am »
I just feel it's sad that those who wanted to create an ultimate OS for everyone would settle on a time format which couldn't even make it to 2050, let alone 2100.  Maybe this short-sight means unix should be dumped?

isn't most platforms and timestamps 64bit already?
It's not that, it's that they begun with only 31bits of time expecting that they would burn, fail and be completely forgotten by 2038.
 
The following users thanked this post: xrunner

Online Monkeh

  • Super Contributor
  • ***
  • Posts: 8134
  • Country: gb
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #5 on: May 05, 2022, 01:53:59 am »
I just feel it's sad that those who wanted to create an ultimate OS for everyone would settle on a time format which couldn't even make it to 2050, let alone 2100.  Maybe this short-sight means unix should be dumped?

You seem to have a very warped idea of how Unix came to be.
 
The following users thanked this post: hans, Siwastaja, tooki

Offline timenutgoblin

  • Regular Contributor
  • *
  • Posts: 189
  • Country: au
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #6 on: May 05, 2022, 01:54:27 am »
We all know that if nothing is done, UNIX will conk out early 2038 because there are 2^31 seconds from 1 January 1970 till 19th January 2038.

Yep, we're all doomed and there is nothing we can do to stop it.

link to the video here: https://youtu.be/l4UFQWKjy_I
 
The following users thanked this post: BrianHG

Offline ejeffrey

  • Super Contributor
  • ***
  • Posts: 4033
  • Country: us
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #7 on: May 05, 2022, 05:34:22 am »
The only reason I can think of is, being signed, it could also deal with negative numbers, that is, dates earlier than 1 January 1970. Does that make any sense at all? Is that how it works?

Yes.  While UNIX timestamps themselves are rarely negative, it's common to subtract two timestamps to compute the delta between them.  If you do that with unsigned types in C the result will be unsigned and wrap to a large positive value for negative deltas.

C was also built around the idea of having the basic integer types be of an unspecified width that could be changed to fit the machine in question.  To the extent anyone in the 70s worried about Y2.038k, they probably just assumed that changing the type would be no problem.  The expectations of binary compatibility and stronger portability were a lot less then than now.
 
The following users thanked this post: eugene

Offline daqq

  • Super Contributor
  • ***
  • Posts: 2321
  • Country: sk
    • My site
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #8 on: May 05, 2022, 06:42:37 am »
Like most bad things: It seemed good at the time.
Believe it or not, pointy haired people do exist!
+++Divide By Cucumber Error. Please Reinstall Universe And Reboot +++
 
The following users thanked this post: newbrain

Offline JohanH

  • Frequent Contributor
  • **
  • Posts: 669
  • Country: fi
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #9 on: May 05, 2022, 06:54:46 am »

isn't most platforms and timestamps 64bit already?

In *BSD and Linux most things are fixed. And what is not fixed is planned for.

But there are a lot of old software running out there. I've even seen old SCADA type of software on Windows that rely on 32-bit timestamp for some functions. I verified by changing computer date and time and a certain function stopped working in 2038. Nothing critical in this example, though.

There was some joking why Germans wanted to stop their nuclear power plants before 2038...
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #10 on: May 05, 2022, 03:44:49 pm »
To the extent anyone in the 70s worried about Y2.038k

Thank you for writing Y2.038k instead of the more common and completely incorrect Y2K38.
 

Offline nightfire

  • Frequent Contributor
  • **
  • Posts: 587
  • Country: de
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #11 on: May 05, 2022, 09:28:54 pm »
No- back then, Memory and resources were scarce, and by that time the decision was made, the designers were full aware that it would have some limitations- but by year 2038 there would be more powerful systems available, so it was expected that by then a solution/updated version would be available.
 

Offline SiliconWizard

  • Super Contributor
  • ***
  • Posts: 15797
  • Country: fr
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #12 on: May 05, 2022, 09:48:39 pm »
No- back then, Memory and resources were scarce, and by that time the decision was made, the designers were full aware that it would have some limitations- but by year 2038 there would be more powerful systems available, so it was expected that by then a solution/updated version would be available.

Yeah, sounds reasonable. And actually, the updates have been there for quite a while already.
Those still running old software for whatever reason, even if the reason is a good one, are responsible. Not the authors of 50 years ago. Come on. =)
 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 7508
  • Country: va
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #13 on: May 08, 2022, 09:05:04 pm »
To the extent anyone in the 70s worried about Y2.038k

Thank you for writing Y2.038k instead of the more common and completely incorrect Y2K38.

For an EE, why would the second not be correct? In fact, wouldn't Y2038 be the actual correct way - Y2K was, after all, just an abbreviation that appealed to computer types and could be mistaken for meaning Y2024.
 

Offline langwadt

  • Super Contributor
  • ***
  • Posts: 4857
  • Country: dk
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #14 on: May 08, 2022, 10:24:40 pm »
To the extent anyone in the 70s worried about Y2.038k

Thank you for writing Y2.038k instead of the more common and completely incorrect Y2K38.

For an EE, why would the second not be correct? In fact, wouldn't Y2038 be the actual correct way - Y2K was, after all, just an abbreviation that appealed to computer types and could be mistaken for meaning Y2024.

Y2K38 would 2380, so if anything it should be Y2K038

 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 7508
  • Country: va
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #15 on: May 08, 2022, 11:49:25 pm »
Quote
Y2K38 would 2380, so if anything it should be Y2K038

Ah, good point :)
 

Offline Nominal Animal

  • Super Contributor
  • ***
  • Posts: 7192
  • Country: fi
    • My home page and email address
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #16 on: May 09, 2022, 02:39:07 pm »
To the extent anyone in the 70s worried about Y2.038k

Thank you for writing Y2.038k instead of the more common and completely incorrect Y2K38.

For an EE, why would the second not be correct? In fact, wouldn't Y2038 be the actual correct way - Y2K was, after all, just an abbreviation that appealed to computer types and could be mistaken for meaning Y2024.
Not 2024, 211=2048.
 

Offline PlainName

  • Super Contributor
  • ***
  • Posts: 7508
  • Country: va
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #17 on: May 09, 2022, 03:04:37 pm »
Quote
Not 2024, 211=2048.

Just checking if you're awake  :P
 
The following users thanked this post: Nominal Animal

Offline eugene

  • Frequent Contributor
  • **
  • Posts: 497
  • Country: us
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #18 on: May 10, 2022, 06:10:07 pm »
We have 14 years to convert to 256 bit time stamps. That should work until our sun burns out or goes supernova or whatever. If you move to another solar system then you're on your own.
90% of quoted statistics are fictional
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1698
  • Country: nl
Re: UNIX rollover - why 2^31 signed and not 2^32 unsigned?
« Reply #19 on: May 10, 2022, 08:54:26 pm »
It's not that, it's that they begun with only 31bits of time expecting that they would burn, fail and be completely forgotten by 2038.

And so did Microsoft never thought they would stay around long enough to reach Windows 9 :horse:

Isn't any technology going to have limitations that were unforeseen or planned to be part of future drafts? I mean C is a wonderfully simple language.. but you wouldn't want to program absolutely everything in it neither.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf