Why dosen´t this work?

Started by
14 comments, last by peter86 21 years, 4 months ago
quote:Original post by SysOp_1101
AFAIK, there is no ''or'' keyword in C++


Actually, there is such a keyword. It''s an alternative token for ||.
Advertisement
quote:Original post by spock
Actually, there is such a keyword. It's an alternative token for ||.

Are you sure that's a standard C++ keyword? I can imagine compilers implementing this as a macro, but ...

[edited by - Miserable on December 3, 2002 6:50:28 PM]
quote:
Actually, there is such a keyword. It''s an alternative token for ||.


I stand corrected. After consulting the ''tome of Stroustrup'' I found that the ''or'' keyword was indeed valid (as well as a few others and some ''hairy'' looking digraphs and trigraphs). Thanks for pointing that out spock. :D
SysOp_1101
quote:Original post by felisandria
... unless something is REALLY wrong, equal operators will always be successful.
Unless my brain is REALLY tired, (x = 0) should not evaluate to true.

quote:Original post by peter86
Wouldn´t this work either?:

if( i = ( j | k ) )


I still haven´t got any answear to this.
What do you mean "it doesn''t work"? Compiler error? Wrong behaviour? Doesn''t evaluate to what you want?

Please explain what you want to achive, and the necessary context of the code you provide. We do not have a clue what types the variables are that you''re using.

First,
if( i = ( j | k ) )
This has no meaning if i, j and k are booleans, floats, etc. Otherwise, if they are integers, it will first evaluate the expression (j | k) (bitwise OR of j and k), then assign that value to i. Last, if the value of i evaluates to true (ie. not zero) it will execute the following statement or code block.

If it is that you want, it works, otherwise it doesn''t.

If you are looking for an expression that evaluates to true if i equals either of j or k, then you should have this:
if((i == j) || (i == k))

If that''s not what you''re looking for, please describe your problem properly.

This topic is closed to new replies.

Advertisement