Search code examples
coctalkernighan-and-ritchie

K&R C handling the octals


So, firstly I have read the following: http://www.hpc.unimelb.edu.au/nec/g1af02e/chap1.html It tells me the following:

K&R C and SUPER-UX K&R C The digits 8 and 9 are allowed. They are considered decimal integer constants.

I have got a little bit confused... Looked out for some more ... found this: http://docs.oracle.com/cd/E19205-01/819-5265/bjbfb/index.html

It tells me this:

Accepts 8 or 9 in octal escape sequences.

But, according to: http://en.wikipedia.org/wiki/Octal

The octal numeral system, or oct for short, is the base-8 number system, and uses the digits 0 to 7.

And now I am really confused. I have never had the chance to actually have to work with a K&R C compiler... so why does K&R C accept 8 and 9 as octal digits... How is this handled? What will be their value in a "real" octal system?


Solution

  • K&R C was not very strict, so a lot of things that an ANSI-C (and newer) compiler disallows was allowed.

    The "octal" number 0193 would be the equivalent of 1*8^2 + 9*8^1 + 3. An abomination? Yes.