fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Logical OR operators

Logical OR operators 11 months 3 weeks ago #5682

  George's Avatar Topic Author George Offline Posts: 91
Trying to run a former Vulcan App compiled with X# (with Vulcan RUntime of course), I noticed a difference in Logical OR operators.

My App had the code:

LOCAL aStr AS STRING[]
...
IF aStr <> NULL || aStr:Length < 1
...
ENDIF

The X# runtime error is:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.

then, I replaced the || with .OR.
IF aStr <> NULL .OR. aStr:Length < 1
...
ENDIF

the error disappeared!

So, if the || operator is used, BOTH conditions are checked.
In contrast, by using the .OR. operator, when the 1st condition is TRUE then the 2nd is ignored.

Is-it the correct operators' behaviour in X#, or the || operator had to behave like the .OR. operator and it's a bug?

regards
George

Please Log in or Create an account to join the conversation.

Logical OR operators 11 months 3 weeks ago #5686

  Chris's Avatar Chris Offline Posts: 1226
Hi George,

Yes, this is a compiler bug, apparently the || symbol in this code gets translated to the binary OR operator, instead of the logical OR operator as it should, causing both operands to be evaluated always. And the same bug exists with &&/AND also.

Thanks a lot for reporting this, I think it will be possible to fix this soon.

Chris
XSharp Development Team
chris(at)xsharp.eu

Please Log in or Create an account to join the conversation.

  • Page:
  • 1