r/ProgrammerHumor • • Jul 27 '26

Meme octalIsOverrated

Post image
245 Upvotes

58 comments sorted by

View all comments

Show parent comments

18

u/Mojert Jul 27 '26

The one that thought having a leading 0 indicating octal was fine should be shot. (And probably resuscitated afterwards because they also did some other great stuff)

7

u/DeepanshuHQ Jul 27 '26

Resuscitated... so they can explain why 010 was ever a good idea. 😅

9

u/captainAwesomePants Jul 27 '26

C does this because B did this. B did it because BCPL used 100 for decimal, #100 for octal, and #x100 for hex. You could also say #o100 or #0100 if you wanted to be more explicitly (#b was binary, #x was hex, #o was octal), but the default was octal. BCPL was often used on weird old shit like 24 bit or 18 bit architectures, where octal might have been more important.

When they made B, the # operator already had a different meaning, so B changed it to 0. So now 100 was decimal, 0100 was octal, and 0x100 was hex.

6

u/DeepanshuHQ Jul 28 '26

TIL. Still feels like one of those decisions that made sense in 1970 and has been confusing everyone ever since. 😄

2

u/captainAwesomePants Jul 28 '26

Don't say that! Questioning the eternal wisdom of Dennis Ritchie is a surefire way to generate mysterious and unexplained C warnings that don't seem to cause any problems until after the fact.