6 ms·
Why a signed int?
by fguerraz 3y ago
Why a signed int?
- vore 3y agotime_t has historically been a typedef to a 32-bit signed integer, so the signedness is baked into a lot of legacy software still running today.
- CableNinja 3y agoAfaik this is so that you can go back in time before epoch (less than 0)
- avgcorrection 3y agoThen why not start the epoch however far back they thought they need to go back? Maybe a naive question.
- School-Cotton 3y agoWhether you make 0 be in 1902 and use an unsigned type, or make 0 be in 1970 and use a signed type, the range of representable dates is the same.
- avgcorrection 3y agoSure. But (and what I should have added) I don't think they would need to go back that far. But you're right, you can get the same results with both.
- School-Cotton 3y agoAs others have pointed out in the thread, it was already not enough to represent the dates of birth of plenty of people who were still alive in 1970.
- avgcorrection 3y agoGood point. :)
- arcticbull 3y agoYou may need an arbitrary distance back in time, so really any epoch is as good as any other. So if you're going to pick arbitrarily, zero around where most numbers are going to be when you set the standard seems to make sense.
- faraggi 3y agoWas the negative sign commonly used for delta times?
- SAI_Peregrinus 3y agoThe epoch was set very close to the start of UNIX (it started development in 1969, before epoch 0). Negative epoch dates are quite common, e.g. many people's birthdays.
- gene91 3y agoIn 1970, I suppose there are many people whose birthdate is before 1901-12-13?
- SAI_Peregrinus 3y ago0 UNIX epoch is 1970-01-01. So everyone between 1901 and 1970 have negative birthdays in UNIX time. E.g. Brian Keringhan's birthday is -881107200 in UNIX time.
- uoaei 3y agoConverting to unsigned int only changes the first digit (6 becomes e) but I think `e5075ea9` is a little easier to reason about.
- deleted 3y ago[deleted]
- omoikane 3y agotime_t is now 64 bits.[1] The change probably happened around 2014.[2] [1] https://gcc.godbolt.org/z/Wv99v4W6E https://gcc.godbolt.org/z/Wv99v4W6E [2] https://lwn.net/Articles/598408/ https://lwn.net/Articles/598408/
- School-Cotton 3y agoUsing a signed int allows you to represent times before 1970. This is not just theoretical; it’s done in the wild. Materialize, the data warehouse software I work on, used to have a bug causing it to fail on negative Unix times and we found out when somebody tried to load in a database with human dates of birth.
- NooneAtAll3 3y ago2018-July-22 was the last day "that wouldn't work for all people" excuse was true. Chiyo Miyako was born on 1901-May-02
- spartanatreyu 3y agoYeah, but now when you try to load in a database of documents (e.g. legal, blueprints, etc...), the date the document was created crashes everything instead.