|
|
|
[
Permlink
| « Hide
]
Lex Neva added a comment - 17/Sep/07 08:59 AM
Why is this a problem? -1 is still equivalent to a true boolean value.
It is a problem because TRUE == 1 != -1. These two comparisons should both evaluate to true
( "a" != "b" ) == TRUE but they don't. I'm pretty sure this same thing happens in a lot of languages, such as C/C++. Conditional statements like if(foo) really test whether foo is not equal to zero. Any nonzero value is equivalent to a true boolean value. TRUE is just a convenient constant that happens to equate to a true boolean value. I don't think the behavior you're seeing needs to be changed. Just don't do anything silly like add up values returned by !=.
I don't see any reason why the expression should return different values for the same logical comparison - despite the fact that in C++ the following char comparisons do return 1 in both cases:
Code: Result: Well, we'll let the Lindens decide I suppose In your c++ example you are doing single character comparisons which is very different beast. A single character comparison in C++ is an integer based operation.
A != operator used on character arrays in C++ would just compare the pointers and would always return false (assuming the compiler hadn't optimized the constant strings). To compare character arrays in C++ you use strcmp, which is what the LSL VM does (it was written in C++). strcmp is part of the ANSI C standard. "Fixing" this would break existing code. Okay, I am convinced. ^^ I'll close this issue now.
I would like to propose a reopening of this issue and that the chance to fix this as mono is introduced be taken.
One should treat the EQUALITY and INEQUALITY operator as the way the operations of EQUALITY are defined, with the only valid outcomes being TRUE (1) and FALSE (0). Motivation: 2) The operators != and == are per definition NOT string comparsion (C::strcmp) operators in any other language. 3) The behavior is inconsistent with the other types' operators, most specifically this is utter nonsense: 4) In the lack of a C++ expression like this: One might want to replace with: Which won't work reliably with the current definition of the string operator. Correction to above "semi C+" example. The correct way to do it (in C+) is: #include <iostream> Which will indeed print 1as one would expect. Proposed solution: |
|||||||||||||||||||||||||||||||||||||||||||||