473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

010 is 8 and not 10 :(

Hi,

I find that numbers beginning with a zero are evaluated in base 8.

Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};

I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.

This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?

Thx,
Karthik Balaguru

Sep 13 '07 #1
35 2251
karthikbalaguru wrote:
Hi,

I find that numbers beginning with a zero are evaluated in base 8.

Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};

I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.

This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?
Such as?

The convention goes back a long way and is never likely to change.

--
Ian Collins.
Sep 13 '07 #2
karthikbalaguru <ka***************@gmail.comwrote:
I find that numbers beginning with a zero are evaluated in base 8.
No shit, Sherlock. This is how C is, and always has been. Deal.

Richard
Sep 13 '07 #3
On Sep 13, 12:40 pm, karthikbalaguru <karthikbalagur...@gmail.com>
wrote:
Hi,

I find that numbers beginning with a zero are evaluated in base 8.

Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};

I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.

This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?

Thx,
Karthik Balaguru
It should be : (No comma in the earlier snapshot of code)

Example -
int numbers[] = { 001,
010 // This is treated as 8 and not as 10 :
( Strange :(:(
};

Thx,
Karthik Balaguru

Sep 13 '07 #4
karthikbalaguru wrote:
Hi,

I find that numbers beginning with a zero are evaluated in base 8.
Exactly as defined by the language.
>
Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
No it's not. Anyone who was awake during the first day of their lessons
in C knows that integers represented by 0 followed by digits are octal
and integers represented by 0x or 0X followed by digits are hex.
But some people don't stay awake in class or read their textbooks and
then call the obvious strange.
I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.
You were shocked by what you should have known, had you not been
comatose. How strange.
>
This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?
That things are just fine as they are, as long as you don't ever get a
programming job, or at least until your attention span grows to, say, 15
seconds.

Sep 13 '07 #5
karthikbalaguru wrote:
Hi,

I find that numbers beginning with a zero are evaluated in base 8.

Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};

I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.

This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?
If you find that this is a problem, there are editors which highlight octal
constants (such as 010) in a different colour to decimal constants (such as 10)
to make it obvious that it means something different.

Philip

--
Philip Potter pgp <atdoc.ic.ac.uk
Sep 13 '07 #6
On Sep 13, 1:55 pm, Philip Potter <p...@see.sig.invalidwrote:
karthikbalaguru wrote:
Hi,
I find that numbers beginning with a zero are evaluated in base 8.
Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};
I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.
This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?

If you find that this is a problem, there are editors which highlight octal
constants (such as 010) in a different colour to decimal constants (such as 10)
to make it obvious that it means something different.

Philip

--
Philip Potter pgp <atdoc.ic.ac.uk- Hide quoted text -

- Show quoted text -
Thats a coool idea to avoid mistakes without requesting a change in C
Language.
Thx.

Karthik Balaguru

Sep 13 '07 #7
karthikbalaguru wrote:
On Sep 13, 1:55 pm, Philip Potter <p...@see.sig.invalidwrote:
>karthikbalaguru wrote:
>>Hi,
I find that numbers beginning with a zero are evaluated in base 8.
>If you find that this is a problem, there are editors which highlight octal
constants (such as 010) in a different colour to decimal constants (such as 10)
to make it obvious that it means something different.
Thats a coool idea to avoid mistakes without requesting a change in C
Language.
I think you should request the change, just to see what response you get...
Sep 13 '07 #8
In article <11*********************@o80g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrites
>On Sep 13, 1:55 pm, Philip Potter <p...@see.sig.invalidwrote:
>karthikbalaguru wrote:
Hi,
I find that numbers beginning with a zero are evaluated in base 8.
Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};
I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.
This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?

If you find that this is a problem, there are editors which highlight octal
constants (such as 010) in a different colour to decimal constants
(such as 10)
to make it obvious that it means something different.

Philip

--
Philip Potter pgp <atdoc.ic.ac.uk- Hide quoted text -

- Show quoted text -

Thats a coool idea to avoid mistakes without requesting a change in C
Language.
Thx.

Karthik Balaguru
1
"cool" wasn't cool the first time it was in fashion 40 years ago. I
remind my "cool" sons about that. "Man" and "dude" are also back.
Nostalgia isn't etc... :-)

2
Syntax highlighting has been around almost as long as colour monitors.
(About 25 years.) Strangely that is no recognised standard for colour
highlighting.

3
Octal constants have always been in the C language. If you did not know
that you need a BASIC course in C programming.

4
Many coding standards ban the use of Octal constants

5
0.123 is a FLOAT not an Octal number :-)

6
Request for change in C language denied

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Sep 13 '07 #9
Chris Hills wrote:
In article <11*********************@o80g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrites
>Thats a coool idea to avoid mistakes without requesting a change in C
Language.
Thx.

Karthik Balaguru

1
"cool" wasn't cool the first time it was in fashion 40 years ago. I
remind my "cool" sons about that. "Man" and "dude" are also back.
Nostalgia isn't etc... :-)
Strange, I can't find any reference to "cool" in the C standard. It must be a
compiler extension on his platform :)
2
Syntax highlighting has been around almost as long as colour monitors.
(About 25 years.) Strangely that is no recognised standard for colour
highlighting.
Yes, but some syntax highlighters do not distinguish octal constants from
decimal constants. The OP may have this problem.
3
Octal constants have always been in the C language. If you did not know
that you need a BASIC course in C programming.
Or perhaps he forgot? Quite reasonable for a beginner; he might have read the
relevant section, but since octal constants are so rarely used there's little to
back up the learning process. I only really remember about octal constants
because my editor colours them in.
5
0.123 is a FLOAT not an Octal number :-)
Actually, it's a double. 0.123f is a float.

--
Philip Potter pgp <atdoc.ic.ac.uk
Sep 13 '07 #10
In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>I find that numbers beginning with a zero are evaluated in base 8.
Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 13 '07 #11
Richard Tobin wrote:
In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.
dmr should probably have used a convention analogous to that for
hexadecimal. Hex is indicated by a zero followed by a letter 'x', I
suggest octal could have been indicated by a zero followed by a letter
'o'...
Sep 13 '07 #12
In article <5k************@mid.individual.net>,
Martin Ambuhl <ma*****@earthlink.netspewed a bunch of hyper-active
sh*t, ending with:
>That things are just fine as they are, as long as you don't ever get a
programming job, or at least until your attention span grows to, say, 15
seconds.
Paramedics are being dispatched to the home of "Martin Ambuhl" as we speak.

Don't worry; help is on the way.

Sep 13 '07 #13
"Mark Bluemel" <ma**********@pobox.coma écrit dans le message de news:
fc**********@aioe.org...
Richard Tobin wrote:
>In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.

dmr should probably have used a convention analogous to that for
hexadecimal. Hex is indicated by a zero followed by a letter 'x', I
suggest octal could have been indicated by a zero followed by a letter
'o'...
I have a more general suggestion, compatible with the preprocessor token
definitions:

[decimal number between 0 and 36] 'x' [digits or letters within the
constraint of the base specified before the x]

for example the decimal value 10 could be represented as:

2x1010 3x101 4x22 5x20 6x14 7x13 8x12 9x11 10x10 11xa 11xA ...

base 1 is a special case: 1x1111111111 but also 1x101010101011111000 ... and
infinitely many variations.

--
Chqrlie.
Sep 13 '07 #14
"Charlie Gordon" <ne**@chqrlie.orgschrieb im Newsbeitrag
news:46***********************@news.free.fr...
"Mark Bluemel" <ma**********@pobox.coma écrit dans le message de news:
fc**********@aioe.org...
>Richard Tobin wrote:
>>In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:

I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.

dmr should probably have used a convention analogous to that for
hexadecimal. Hex is indicated by a zero followed by a letter 'x', I
suggest octal could have been indicated by a zero followed by a letter
'o'...

I have a more general suggestion, compatible with the preprocessor token
definitions:

[decimal number between 0 and 36] 'x' [digits or letters within the
constraint of the base specified before the x]

for example the decimal value 10 could be represented as:

2x1010 3x101 4x22 5x20 6x14 7x13 8x12 9x11 10x10 11xa 11xA ...

base 1 is a special case: 1x1111111111 but also 1x101010101011111000 ...
and infinitely many variations.
base 1 won't have 1s, only 0s would it?
Sep 13 '07 #15
On Sep 14, 12:12 am, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
Paramedics are being dispatched to the home of "Martin Ambuhl" as we speak.

Don't worry; help is on the way.
Are they riding in an Ambuhlance?

Sep 13 '07 #16
Joachim Schmitz wrote:
"Charlie Gordon" <ne**@chqrlie.orgschrieb im Newsbeitrag
>base 1 is a special case: 1x1111111111 but also 1x101010101011111000 ...
and infinitely many variations.
base 1 won't have 1s, only 0s would it?
`1` is the traditional token.

--
Chris "deeply conservative. no, really." Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Sep 13 '07 #17
Mark Bluemel wrote:
Richard Tobin wrote:
>In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.

dmr should probably have used a convention analogous to that for
hexadecimal. Hex is indicated by a zero followed by a letter 'x', I
suggest octal could have been indicated by a zero followed by a letter
'o'...
Maybe he was concerned about "oh" vs. "zero" confusion? I don't know
about you folks, but I try to never mix "oh" and "zero" in variable
names specifically to avoid this particular problem.
Still, I do agree in spirit with the OP that the C use of a leading zero
to have a special meaning was a bit daft. It's almost like it was an
inside joke: often one can't distinguish "oh" from "zero", so rather
than having an octal constant be "oh"37 we'll make it "zero"37.

Not that this will ever change at this late date but I always thought
the syntax from (most versions?) of Fortran to be much clearer: '0A'x,
'13'o, or 10. Apparently in recent versions of Fortran the letter can
also precede the string.

Regards,

David Mathog
Sep 13 '07 #18
Mark Bluemel <ma**********@pobox.comwrites:
Richard Tobin wrote:
>In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.

dmr should probably have used a convention analogous to that for
hexadecimal.
The leading 0 notation comes from B into C so maybe K Thompson is the
one who decided on that (although DMR had a hand in B too).

It does not come from BCPL into B (BCPL was often cited as a precursor
to B). BCPL has #o77, #b11111 and #x3F together with the convenience
of having _ ignored in numbers (1_234_567 and #x_FF_FE_EB are all
legal). It seems a shame that newer languages do not always have the
best from the older ones!

--
Ben.
Sep 13 '07 #19
In article <11**********************@g4g2000hsf.googlegroups. com>,
Old Wolf <ol*****@inspire.net.nzwrote:
>On Sep 14, 12:12 am, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
>Paramedics are being dispatched to the home of "Martin Ambuhl" as we speak.

Don't worry; help is on the way.

Are they riding in an Ambuhlance?
You may have a point there.

And note, BTW, that MHA actually posts like a human being on other
groups (specifically, RGB, where I find his posts worth reading).
But, for some reason, CLC just brings out the lunatic in him.

Sep 13 '07 #20
On Thu, 13 Sep 2007 00:40:22 -0700, karthikbalaguru
<ka***************@gmail.comwrote:
>Hi,

I find that numbers beginning with a zero are evaluated in base 8.

Example -
int numbers[] = { 001,
010, // This is treated as 8 and
not as 10 :( Strange :(:(
};

I find that compiler does not complain and continues performing after
converting the octal to the corresponding decimal value :(:(.
Initially i was shocked , But later practised to it.

This option of '0' before a number to treat it as octal in C causes
problem sometimes(Easy path for error) .
Octal, we just have a 0 infront of the number in 'C' .
There should be someother convention ? What do you think ?
It's more than a convention, it's part of the C language standard.

Numbers starting with '0' are octal, numbers starting with '0x' or
'0X' are hexadecimal.

--
Al Balmer
Sun City, AZ
Sep 13 '07 #21
Philip Potter <pg*@see.sig.invalidwrites:
[...]
Or perhaps he forgot? Quite reasonable for a beginner; he might have
read the relevant section, but since octal constants are so rarely
used there's little to back up the learning process. I only really
remember about octal constants because my editor colours them in.
I use octal constants all the time. Well, actually, only one
particular octal constant.

0

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 13 '07 #22
David Mathog wrote:
Mark Bluemel wrote:
....
>dmr should probably have used a convention analogous to that for
hexadecimal. Hex is indicated by a zero followed by a letter 'x', I
suggest octal could have been indicated by a zero followed by a letter
'o'...

Maybe he was concerned about "oh" vs. "zero" confusion? I don't know
about you folks, but I try to never mix "oh" and "zero" in variable
names specifically to avoid this particular problem.
Whoosh!
Sep 14 '07 #23
On Thu, 13 Sep 2007 11:16:06 +0000, Richard Tobin wrote:
In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.

Yes, this is the convention used by C. There's no chance of changing
it - it would break existing programs - but I doubt anyone designing
a programming language now would use such an error-prone convention.
Python uses it, too.
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes†feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 14 '07 #24
Army1987 wrote:
On Thu, 13 Sep 2007 11:16:06 +0000, Richard Tobin wrote:
>In article <11*********************@k79g2000hse.googlegroups. com>,
karthikbalaguru <ka***************@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.
>Yes, this is the convention used by C.
Python uses it, too.
As does Java, unsurprisingly.
Sep 14 '07 #25
Keith Thompson wrote:
I use octal constants all the time. Well, actually, only one
particular octal constant.

0
Is that really an octal constant? After all, 0x isn't a hex constant...

--
Philip Potter pgp <atdoc.ic.ac.uk
Sep 14 '07 #26
Philip Potter said:
Keith Thompson wrote:
>I use octal constants all the time. Well, actually, only one
particular octal constant.

0

Is that really an octal constant?
Yes. The Standard says, in 6.4.4.1 (this is C99 btw but it's the same
deal in C90):
3 A decimal constant begins with a nonzero digit and consists of a
sequence of decimal digits. An octal constant consists of the prefix 0
optionally followed by a sequence of the digits 0 through 7 only. A
hexadecimal constant consists of the prefix 0x or 0X followed by a
sequence of the decimal digits and the letters a (or A) through f (or
F) with values 10 through 15 respectively.

After all, 0x isn't a hex
constant...
True enough, although it can be as much as two thirds of a hex constant.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 14 '07 #27
On Sep 14, 6:59 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
Army1987 wrote:
On Thu, 13 Sep 2007 11:16:06 +0000, Richard Tobin wrote:
In article <1189669222.895289.45...@k79g2000hse.googlegroups. com>,
karthikbalaguru <karthikbalagur...@gmail.comwrote:
>I find that numbers beginning with a zero are evaluated in base 8.
Yes, this is the convention used by C.
Python uses it, too.

As does Java, unsurprisingly.
Actually, due to the influence of C and due to the fact that most
newer and modern languages are in fact implemented in C this
convention is the norm. Perl use it, Javascript use it, even the new-
kid-on-the-block Ruby use it.
Tcl is one language that currently also use this convention but is in
the process of getting rid of it - the consensus in the tcl community
is that this is a bug and nobody really uses it. Of course, such raise-
your-hand voting stunt to check if removing 0 octals breaks anyone's
code and getting them to agree to fix it when the change comes is not
feasible for C or any other language with a user base larger than Tcl.
Sep 14 '07 #28
"sl*******@yahoo.com" <sl*******@gmail.coma écrit dans le message de news:
11**********************@w3g2000hsg.googlegroups.c om...
On Sep 14, 6:59 pm, Mark Bluemel <mark_blue...@pobox.comwrote:
>Army1987 wrote:
On Thu, 13 Sep 2007 11:16:06 +0000, Richard Tobin wrote:
>In article <1189669222.895289.45...@k79g2000hse.googlegroups. com>,
karthikbalaguru <karthikbalagur...@gmail.comwrote:
>>I find that numbers beginning with a zero are evaluated in base 8.
Yes, this is the convention used by C.
Python uses it, too.

As does Java, unsurprisingly.

Actually, due to the influence of C and due to the fact that most
newer and modern languages are in fact implemented in C this
convention is the norm. Perl use it, Javascript use it, even the new-
kid-on-the-block Ruby use it.
The case of Javascript is not final:

ECMA 262 (ECMAScript, the Standard for javascript)

B.1 Additional Syntax

Past editions of ECMAScript have included additional syntax and semantics
for specifying octal literals and
octal escape sequences. These have been removed from this edition of
ECMAScript. This non-normative
annex presents uniform syntax and semantics for octal literals and octal
escape sequences for compatibility
with some older ECMAScript programs.

The C octal syntax is no longer recognized except for the number 0.

--
Chqrlie.
Sep 14 '07 #29
On Thu, 13 Sep 2007 04:09:56 -0400, Martin Ambuhl wrote:
karthikbalaguru wrote:
> 010, // This is treated as 8 and
not as 10 :( Strange :(:(

No it's not. Anyone who was awake during the first day of their lessons
in C knows that integers represented by 0 followed by digits are octal
and integers represented by 0x or 0X followed by digits are hex.
But some people don't stay awake in class or read their textbooks and
then call the obvious strange.
Not everyone who teaches C or writes books about C knows C. For
example, I was never told about octal constants in my class, and
the textbook I used didn't know about them (or about the fact that
main() returns an int, either...)
[snip insults to the OP]
--
Army1987 (Replace "NOSPAM" with "email")
If you're sending e-mail from a Windows machine, turn off Microsoft's
stupid “Smart Quotes†feature. This is so you'll avoid sprinkling garbage
characters through your mail. -- Eric S. Raymond and Rick Moen

Sep 15 '07 #30
Groovy hepcat David Mathog was jivin' in comp.lang.c on Fri, 14 Sep 2007
1:44 am. It's a cool scene! Dig it.
Still, I do agree in spirit with the OP that the C use of a leading
zero
to have a special meaning was a bit daft. It's almost like it was an
inside joke: often one can't distinguish "oh" from "zero", so rather
than having an octal constant be "oh"37 we'll make it "zero"37.
I am guessing, but I reckon I know why zero was chosen. When a C
parser fetches a token from a lexical analyser, how does the lexical
analyser determine whether to send back an identifier or an octal
number? A token consisting of the letter 'o' (upper or lower case)
followed by one or more digits is an identifier, not a number. Thus, an
octal number must be a token consisting of a zero optionally followed
by digits from 0 to 7.
It's simple when you think about it, really.

--
Dig the sig!

----------- Peter 'Shaggy' Haywood ------------
Ain't I'm a dawg!!

Sep 19 '07 #31
Peter wrote:
) I am guessing, but I reckon I know why zero was chosen. When a C
) parser fetches a token from a lexical analyser, how does the lexical
) analyser determine whether to send back an identifier or an octal
) number? A token consisting of the letter 'o' (upper or lower case)
) followed by one or more digits is an identifier, not a number. Thus, an
) octal number must be a token consisting of a zero optionally followed
) by digits from 0 to 7.
) It's simple when you think about it, really.

Or you could have had 0x for hex, 0o for octal and 0b for binary. :-)
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Sep 19 '07 #32
Willem <wi****@stack.nlwrites:
Peter wrote:
) I am guessing, but I reckon I know why zero was chosen. When a C
) parser fetches a token from a lexical analyser, how does the lexical
) analyser determine whether to send back an identifier or an octal
) number? A token consisting of the letter 'o' (upper or lower case)
) followed by one or more digits is an identifier, not a number. Thus, an
) octal number must be a token consisting of a zero optionally followed
) by digits from 0 to 7.
) It's simple when you think about it, really.

Or you could have had 0x for hex, 0o for octal and 0b for binary. :-)
Yes (and Perl does use 0b for binary), but 0o could be written as 0O
unless you specifically disallow it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 19 '07 #33
In article <sl********************@snail.stack.nlWillem <wi****@stack.nlwrites:
Peter wrote:
) I am guessing, but I reckon I know why zero was chosen. When a C
) parser fetches a token from a lexical analyser, how does the lexical
) analyser determine whether to send back an identifier or an octal
) number? A token consisting of the letter 'o' (upper or lower case)
) followed by one or more digits is an identifier, not a number. Thus, an
) octal number must be a token consisting of a zero optionally followed
) by digits from 0 to 7.
) It's simple when you think about it, really.

Or you could have had 0x for hex, 0o for octal and 0b for binary. :-)
Of course. But when C started developing, there was no need for hex, but
there was need for octal. On most machines of that time addresses and
contents of words were expressed in octal. So the preceding 0 for octal
is legacy.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Sep 21 '07 #34
"Dik T. Winter" <Di********@cwi.nla écrit dans le message de news:
Jo********@cwi.nl...
In article <sl********************@snail.stack.nlWillem
<wi****@stack.nlwrites:
Peter wrote:
) I am guessing, but I reckon I know why zero was chosen. When a C
) parser fetches a token from a lexical analyser, how does the lexical
) analyser determine whether to send back an identifier or an octal
) number? A token consisting of the letter 'o' (upper or lower case)
) followed by one or more digits is an identifier, not a number. Thus,
an
) octal number must be a token consisting of a zero optionally followed
) by digits from 0 to 7.
) It's simple when you think about it, really.

Or you could have had 0x for hex, 0o for octal and 0b for binary. :-)

Of course. But when C started developing, there was no need for hex, but
there was need for octal. On most machines of that time addresses and
contents of words were expressed in octal. So the preceding 0 for octal
is legacy.
The reason for octal preference then probably stems from historical word
sizes:
36 bit words = 12 octal digits
18 bit half-words = 6 octal digits
6 or 9 bit chars = 2 or 3 octal digits
and of course unix permissions in groups of 3 bits.

--
Chqrlie.
Sep 21 '07 #35
In article <46***********************@news.free.fr"Charlie Gordon" <ne**@chqrlie.orgwrites:
"Dik T. Winter" <Di********@cwi.nla écrit dans le message de news:
....
Of course. But when C started developing, there was no need for hex, but
there was need for octal. On most machines of that time addresses and
contents of words were expressed in octal. So the preceding 0 for octal
is legacy.

The reason for octal preference then probably stems from historical word
sizes:
36 bit words = 12 octal digits
18 bit half-words = 6 octal digits
6 or 9 bit chars = 2 or 3 octal digits
and of course unix permissions in groups of 3 bits.
Not really. I think it is the other wise around. The (later) preference
of word-sizes that were a multiple of three came from the easily understood
octal arithmetic. Very early machines had strange word-sizes, like 41 (I
think that was the KDF-9). The first machine I ever did work on had a
word-size of 27, the next had 60 bit words. But octal was thoroughly
used in computers, even if the words had 16 bits. (Look at any PDP-11
manual: all information is in octal while it was a 16-bits machine, or
for that matter at the manuals for the Intel 8008 and 8080.) Still now
on Intel processors instructions are better understood if you interprete
them in octal.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Sep 22 '07 #36

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.