Bug? Bug with removing white space in expressions

g7jjf

Member
Licensed User
Longtime User
I am converting some C code to B4A and one of the statements was :

B4X:
obj->rotz -= (rotz < 0) ? -1 : 1;

This literally translated into B4A as :

B4X:
If rotz < 0 Then
  obj.rotz = obj.rotz - -1
Else
  obj.rotz = obj.rotz - 1
End If

However, when I came to compile the code, it failed with :

B4A line: 45
aa = aa - -1
javac 1.6.0_45
src\b4a\example\main.java:851: ')' expected
_aa = (int) (_aa--1);
^
It looks like B4A is stripping out the space between the '-' sign and the '-1' literal causing the compile failure.

I know I should use

B4X:
obj.rotz = obj.rotz + 1

instead but I thought I would mention the bug.

Jon.
 

sorex

Expert
Licensed User
Longtime User
interesting... just did a quick test with a retro machine (C64) and it accepted the -- aswell.
I always bracket wrapped math routines to make it more readable and to prevent issues when a variable could go negative, it's just a habit.
 

Attachments

  • math.png
    math.png
    2.2 KB · Views: 181
Top