dim as integer a, b
iif(rnd, a, b) = 1 '' error
iif(0, a, b) = 1 '' sets b=1, because iif returns a reference to b
The usual behaviour for IIF is to return an Rvalue, and hence to disallow things like assignments or byref modification.
I would say that either IIF should always return Lvalues, or should allow returning Rvalues with non-constant conditions too. (The former is probably the easier of the two.)
In addition to always return by value an estimation of the expression that verifies the condition (at compile-time or at run-time), I suggest adding also a compiler warning if the condition is already solvable at compile time, to highlight that the "IIF" usage is useless in the formal code (unless the user knowingly uses as a condition a constant whose value is a conditional compilation criterion).
Last edit: fxm (freebasic.net) 2017-09-10