(Language nitpick on the subject line: In most non-Indian dialects of
English, "doubt" doesn't make sense in this context; "question" is the
correct word to use.)
In article <fm**********@aioe.org>, Tarique <pe*****@yahoo.comwrote:
>What i would like to know is that isn't int i=- -2;
supposed to mean the same as int i= --2;
Why does the white space become significant here?
When the code is broken up into tokens[1], the compiler will always
take the largest token that it recognizes. So when it sees `--', it
will never interpret that as two `-' operators; it will always treat it
as a single '--' operator. (For the same reason, if you say `---', it
will be tokenized as `--' followed by `-', and never `-' `-' `-' or `-'
`--'.)
When there's a space in between, that prevents the tokenizer from
recognizing a `--' (since the -- operator is spelled `--', without
whitespace in between), so it recognizes it as `-' `-' instead.
This is usually what you want, and in cases where it isn't, it's easier
for both the programmer and the compiler writer to have the programmer
break up tokens that should be distinct instead of having the compiler
try to guess what the programmer meant.
dave
(this does annoy C++ programmers who like to write nested templates, though.)
[1] Compiler geeks will be happy to tell you that this is not part of
parsing, but happens first; parsing takes the tokens (not the
original text that the tokens were extracted from) and identifies
the structure in their arrangement. Deciding what they actually
mean happens after parsing.
--
Dave Vandervies dj3vande at eskimo dot com
Probably still cooler than where daemons come from, so we may still be able
to say "linux has a cooler mascot than BSD" with a straight face.
--Ingvar the Grey in the scary devil monastery