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.
Question
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.
OTHER TIPS
In modern C, since the 1989 ANSI C standard, octal digits are just 0 through 7 (for both octal escapes in character and string literals and integer constants).
K&R C, the (largely obsolete) language described by the 1978 1st edition of Kernighan and Ritchie's "The C Programming Language", permitted 8 and 9 in octal numbers, with the obvious values 8 and 9, respectively.
For example, in modern C the constant 019
is a syntax error, but in K&R C it had the value 17.