A
Anthony Paul
Hello everyone,
I have the following code for testing my expression evaluator (I know
the code doesn't make sense, but it doesn't have to for the purposes
of this test) :
int Z = 5;
int e = Z || Z <<= Z;
My evaluator first evaluates Z, sees that it's true, and doesn't
evaluate the Z <<= Z part. So far so good. Now if I set Z = 0, it
would check Z, find it to be false, and then evaluate Z <<= Z and find
that false as well.
When I test the same code on either gcc or Visual Studio's C++
compiler, I get the "error: lvalue required as left operand of
assignment" error message during compilation. This would make sense if
Z || Z was evaluated first, and then it tried to apply Z <<= Z to the
result of that evaluation, but that can't be now can it? The short-
circuit evaluator clearly separates the expression into two camps :
Camp A : Z
||
Camp B : Z <<= Z
The above should clearly not produce the lvalue required error
message; Z IS an lvalue.
And yet the only possible way I can explain its reasoning is if it
were evaluating the expression as follows :
Camp A : Z || Z
Camp B : (result of Z || Z) <<= Z
But if that's the case, how could it possibly do short-circuit
evaluation?
Strange...
Warm regards,
Anthony
I have the following code for testing my expression evaluator (I know
the code doesn't make sense, but it doesn't have to for the purposes
of this test) :
int Z = 5;
int e = Z || Z <<= Z;
My evaluator first evaluates Z, sees that it's true, and doesn't
evaluate the Z <<= Z part. So far so good. Now if I set Z = 0, it
would check Z, find it to be false, and then evaluate Z <<= Z and find
that false as well.
When I test the same code on either gcc or Visual Studio's C++
compiler, I get the "error: lvalue required as left operand of
assignment" error message during compilation. This would make sense if
Z || Z was evaluated first, and then it tried to apply Z <<= Z to the
result of that evaluation, but that can't be now can it? The short-
circuit evaluator clearly separates the expression into two camps :
Camp A : Z
||
Camp B : Z <<= Z
The above should clearly not produce the lvalue required error
message; Z IS an lvalue.
And yet the only possible way I can explain its reasoning is if it
were evaluating the expression as follows :
Camp A : Z || Z
Camp B : (result of Z || Z) <<= Z
But if that's the case, how could it possibly do short-circuit
evaluation?
Strange...
Warm regards,
Anthony