Not true.
Unless the standard has changed, && and || must be evaluated left to right. In the case of &&, if the left operand is zero, then the right operand is not evaluated. In the case of ||, if the right operand is non-zero, then the right operand is not evaluated. (5.14, 5.15 - X3.159-1989)
Now, as to why the original post didn''t crash. The operand ''p ->IsReady ()'' never requires ''p'' to actually be accessed. This is not a bug in the compiler.
Tim
Interesting compiler bug (maybe).
I think you mean the evaluation order of function-parameters. They can be either left-to-right or right-to-left, thus you shouldn''t write code that depends on the order they are evaluated. That''s compiler dependent, but the order of the parameters for operators are language-dependant and should always be the same (no matter what compiler), otherwise your compiler is broken. Thus the order for || and && in C and C++ is left-to-right.
oops:
you are of course both right - doh - trying to think of too many things at once...
an interesting aside is what happens when you change the operator to ||, only the first part of the expression gets evaluated.
you are of course both right - doh - trying to think of too many things at once...
an interesting aside is what happens when you change the operator to ||, only the first part of the expression gets evaluated.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
I''ve had to read this thread several times just to figure out what some of you were talking about, since it had absolutely nothing to do with poor Dire.Wolf''s question. StarikLesovik was closest in his response, but I think I should clear things up just a little bit.
if (!p && p->IsReady()) {}
expands roughly to this:
if ((p == 0) && Object::IsReady(p)) {}
Object::IsReady() doesn''t use a this pointer, so there''s no reason for access violation.
if (!p && p->IsReady()) {}
expands roughly to this:
if ((p == 0) && Object::IsReady(p)) {}
Object::IsReady() doesn''t use a this pointer, so there''s no reason for access violation.
Interesting language feature.
Thanks for the answer jonnyfish
I guess I wasn''t thinking when I asked the question...hehe.
Dire Wolf
www.digitalfiends.com
Thanks for the answer jonnyfish
![](smile.gif)
Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement