-
December 2nd, 2008, 07:28 AM
#1
Syntax question
I'm really astonished and cannot figure it out ...
Code:
bool Mybool[10][5];
int x,i;
...
if (!Mybool[x],i) { ... }
My intention was obviously to write !Mybool[x][i] but the compiler didn't detect any error ... and I spent a lot of time until I found the mistake.
My question ... what is the compiler doing with this incorrect syntax?
Thks
Did it help? rate it.
The best conversation I had was over forty million years ago ... and that was with a coffee machine.
-
December 2nd, 2008, 07:33 AM
#2
-
December 2nd, 2008, 07:44 AM
#3
Re: Syntax question
well ... I would like to understand/know what is being compiled when an
if (expresion1,expresion2)
is written.
Just "to know" if you like it that way.
Did it help? rate it.
The best conversation I had was over forty million years ago ... and that was with a coffee machine.
-
December 2nd, 2008, 07:53 AM
#4
Re: Syntax question
Expression 1 is evaluated, then expression 2. The result of expression 2 is used by the 'if' to determine program flow.
Your original code is equivalent to...
Code:
!Mybool[x];
if (i) { ... }
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
-
December 2nd, 2008, 05:46 PM
#5
Re: Syntax question
Originally Posted by DeepButi
I'm really astonished and cannot figure it out ...
Code:
bool Mybool[10][5];
int x,i;
...
if (!Mybool[x],i) { ... }
My intention was obviously to write !Mybool[x][i] but the compiler didn't detect any error ... and I spent a lot of time until I found the mistake.
My question ... what is the compiler doing with this incorrect syntax?
Thks
You've stumbled onto the ',' operator. That's why there was no compile error.
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|