Skip to content
DevMeme
5024 of 7435
A Forgotten 'Feature' from Pre-ANSI C
TechHistory Post #5498, on Sep 22, 2023 in TG

A Forgotten 'Feature' from Pre-ANSI C

Description

The image displays a snippet of text from what appears to be a technical document, likely an old C language specification. The text is formatted with section numbers. Section 2.3.1 defines integer constants and notes that an integer is treated as octal if it starts with a 0. The most notable and underlined sentence states: "The digits 8 and 9 have octal value 10 and 11 respectively." A watermark at the bottom right says "More fun at https://t.me/dev_meme". This content is humorous to experienced developers because it highlights a bizarre and counter-intuitive quirk from a very early version of the C programming language (pre-ANSI). In modern C and almost all other languages, octal numbers can only contain digits from 0 to 7. The idea that a parser would accept an invalid octal digit like '8' and interpret it as the octal value '10' is a perfect example of the dangerous and unpredictable behavior that existed in early, less-standardized programming languages

Comments

59
Anonymous ★ Top Pick Some say this is why you can't trust legacy code. The truth is, you can't even trust the legacy compiler that wrote the legacy code
  1. Anonymous ★ Top Pick

    Some say this is why you can't trust legacy code. The truth is, you can't even trust the legacy compiler that wrote the legacy code

  2. Anonymous

    Somewhere an old K&R-era lexer just shrugged and said, “well, *technically* that’s your problem at link-time.”

  3. Anonymous

    This is the kind of language design decision that makes you wonder if Dennis Ritchie was actively trying to create job security for C programmers, or if Bell Labs just had a really aggressive April Fools' culture that got out of hand

  4. Anonymous

    Ah yes, the legendary octal system where 8 and 9 exist - clearly written by someone who thought 'leading zero means octal' was more of a suggestion than a rule. This is the programming equivalent of saying 'the letter Ω has ASCII value 65.' It's the kind of spec that makes you wonder if the manual was compiled with `-Wno-math` and whether the author ever actually *ran* their code, or just shipped the documentation and called it a day. No wonder we have off-by-one errors - we can't even agree on which digits exist in which base

  5. Anonymous

    Nothing ages a codebase faster than a leading zero - 09 becomes a postmortem while someone explains why chmod 0755 is fine but 0855 isn’t

  6. Anonymous

    When docs treat octal like base-12: digits 8=10, 9=11, and your compiler's undefined behavior becomes the real constant

  7. Anonymous

    Legacy C: where 010 equals 8, 011 equals 9, and 09 equals a postmortem (bonus points if your YAML parser agrees)

  8. @Agent1378 2y

    Hahahhahahahgahaha typical C

    1. @RiedleroD 2y

      "pre-ansi C" just means various C dialects from before it was standardized. In many ways, this is the exact opposite of "typical C"

      1. @Agent1378 2y

        I mean the overall feeling of the language, where shooting yourself in the leg is almost inevitable

        1. @RiedleroD 2y

          that's more C++ C is primitive, but it's also possible to know everything there is to know, reducing errors from ignorance

          1. @RiedleroD 2y

            imo of course

  9. @gizlu 2y

    I don't think this fragment means what you mean

    1. @gizlu 2y

      In another edition of this reference this fragment is a bit longer (and surounding context makes it clear) https://www.livingcomputers.org/UI/UserDocs/Unix-v7-1/UNIX_Programmers_Manual_Seventh_Edition_Vol_2_1983.pdf

      1. @deadgnom32 2y

        yeah and octal value of 10 is 8

      2. @deadgnom32 2y

        and octal value of 11 is 9, so what's the problem?

        1. dev_meme 2y

          What you are taking is notation (binary/hex/etc) And no, it’s not like this in (almost) any language of any standard For example let’s take just two most popular languages: JS and Go (but it’s ~same in the rest of popular languages) How do you define octal number? Eg: 0123 - is definition of Octal number thanks to leading 0 Octal number 123 in decimal is 83. Try it in your browser right now

      3. @gizlu 2y

        and this extended fragment with similar (albeit, less vague) note about hex makes me even more confident

  10. @deadgnom32 2y

    you got it wrong they just mean that 8 is 10 in octal not that 8 is interpreted as octal right away. just poor explanation

  11. @deadgnom32 2y

    it is exactly the same in every language even by today

  12. @deadgnom32 2y

    there is no contradiction to what is written in this text

    1. dev_meme 2y

      It is

      1. @deadgnom32 2y

        they say octal notation begins with leading 0 that is true here 8 is VALUE of octal 10 —> 010 9 is VALUE of octal 11 —> 011

  13. @deadgnom32 2y

    yes, because there is no octal 08

    1. dev_meme 2y

      You have misunderstanding of what is notation and how notaions are interpreted by languages

  14. @deadgnom32 2y

    dude

  15. @deadgnom32 2y

    it doesn't exist and will be converted as decimal

    1. dev_meme 2y

      Weirdness highligthed in the bell’s standart is that 8 and 9 was considered to be valid octals

      1. @deadgnom32 2y

        is it so?

    2. dev_meme 2y

      But not in the Bell’s standart

      1. @deadgnom32 2y

        well, then. you are right

  16. @deadgnom32 2y

    but it is still the same. 08 = 010 = 8

    1. dev_meme 2y

      Maybe it will be easier to get the point by adding 2 more lines?

      1. @deadgnom32 2y

        08 = 010 = 8 09 = 011 = 9

        1. dev_meme 2y

          Yeah, so weirdness is that per Bell’s standart there’s 2 ways to define decimal numbers 8 and 9 using octal notation

          1. @deadgnom32 2y

            yes. that is where js is kinda the same as C it tries to interpret your value somehow even if it's bullshit

            1. dev_meme 2y

              Don’t say that you want runtime error when number has leading zero 😄

              1. @deadgnom32 2y

                well, you shouldn't write it like this in a first place, but still if you do, you will get correct result.

                1. dev_meme 2y

                  Most of data is not what we wrote but the data which we got somehow in the process

                  1. dev_meme 2y

                    But allowing language (per standart) to interpret 8 and 9 as valid octals is… wtf? 😄

                    1. @deadgnom32 2y

                      I know where this is handy, but it's a topic too big for this chat

                      1. dev_meme 2y

                        Sure there’s a cases and that’s why no one here is blaming Bell’s engineers for that choice. But it might be a very hard issue to debug when you see numbers with 8 and 9 being received from the user and then somehow during execution it becomes much smaller than it was initially

                      2. dev_meme 2y

                        And hey, that’s C! It wouldn’t take much time to make your octals which would work like in Bell’s standart. But that’s not a common case and not how octals should work in general

                        1. @deadgnom32 2y

                          yeah, you got the point. but they had it more comfortable this way. it still doesn't break any logic. en contraire, it fixes some common input errors automatically. see no problem in that

                      3. dev_meme 2y

                        Otherwise, just as continuation of that idea, we will end up with numbers like 0b12345 being valid binary

                  2. @deadgnom32 2y

                    not in this case. here it is a mere representation inside the code underneath you have just binary

                  3. @deadgnom32 2y

                    in case of input it is either binary straight away, so it will be correctly interpreted anyways. or it is a string, and there you force a way to interpret it, but this is the point. string input can be sick, and this approach helps to fix some of the common errors. if that isn't wanted, you always can validate the input prior to interpretation yourself.

                    1. dev_meme 2y

                      I understood your point. But now if we’re talking about definition of notations in standarts it would be weird that only octals are allowed “overflow” number to be used as valid ones. After this we will have to make one of 3 main decisions: 1) Keep it only for octals (for historical purpose, lol) 2) Allow all notations to use “overflow” number 3) Remove that approach from octals so they act as number of other notations

            2. dev_meme 2y

              But it’s not just JS. I used it to show example as the easier way to experiment

              1. @deadgnom32 2y

                I know

  17. @deadgnom32 2y

    not in decimal in octal

    1. dev_meme 2y

      9 and 10 doesn’t exist in octal notation

      1. @deadgnom32 2y

        but you still get correct result

  18. @deadgnom32 2y

    I do C for about 12 years.

  19. @deadgnom32 2y

    that is, well, wonderful I would say

  20. @gizlu 2y

    I have to confess that I am a bit drunk, but I don't see any convincing arguments in last ~50 messages supporting thesis that "pre-ansi C recognized 8 and 9 as octal digits"

  21. @gizlu 2y

    "The digits 8 and 9 have octal value 10 and 11" just seems to be a vague "explanation" (more like confirmation that it works the way one would think it does) how octal works

  22. @gizlu 2y

    I think that if "8 and 9 are valid octal digits" statement were true, it would be noted more explicitly

  23. @mpolovnev 2y

    Those seem to be examples. If you need 8, please type 010. If you need 9, please type 011 .

Use J and K for navigation