IIF invalid assignment

Previous topic - Next topic

MrTAToad

When using IIF with equality comparison, the variable being compared has it's value changed to that being compares,  For example :

Code (glbasic) Select
LOCAL a%=7
LOCAL b%=0

DEBUG a%+" "+b%+"\n"
b%=IIF(a%=8,1,2)
DEBUG a%+" "+b%+"\n"


In this example, a% gets set to a value of 8 (and b% is set to 1).  a% should be kept at 7, as we're testing for equality and not assigning.

And <> can't be used with this command for some reason.

kanonet

Quote from: MrTAToad on 2014-Jun-11(and b% is set to 1)
This is correct for your example.

But your example gets translated to
Code (glbasic) Select
b=IIF(a=8,1,2); so the GPC fails to translate = to ==. That bug is just an other prove that it was a bad idea to use same operator for assignment and comparison.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

MrTAToad

Indeed - the compiler needs to know = should be used for comparison in IIF and not for value assignment.

Kitty Hello

Oopsie Daisys

Gesendet von meinem GT-N7100 mit Tapatalk


Kitty Hello

Fixed it. It was a bug with the equal sign right of an assignment!
Code (glbasic) Select

LOCAL a% = IIF(1=1, 1, 2)
LOCAL b% = RND(3=4)
LOCAL c% = 4=5=6

works now (next update)

kanonet

It is not fixed in 12.243 the logfile is wrong on this.

The code from 1st post still fails, since "b=IIF(a=35,3,4)" translated to "b=IIF(a=35,3,4);" instead of "b=IIF(a==35,3,4);". Therefore "b=IIF(35=a,3,4);" is not even compiling. :giveup:
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

MrTAToad


Kitty Hello


matchy


Kitty Hello

ok, fixed in next update.