|Think about Loose Coupling|
Re: Trinary Operator Semanticsby pfaut (Priest)
|on May 26, 2005 at 19:39 UTC||Need Help??|
I just compiled your code on a VAX (VMS) both with and without optimization enabled. In each case, both routines generated identical code.
To me, the ternary operator is most useful when used in a function call argument list or other complex expression where one element needs to change based on some condition. These become much easier and concise to express with a ternary operator than with two separate statements within an if/else construct.
What it boils down to is that the ternary operator presents an expression and can be used anywhere an expression can be used. if/else is a (compound) statement and is much more restrictive about where it can be used.
The trinary function is handling the variable between registers, whereas ifelse is using a memory location. This is another boost to the trinary operator.
Doesn't the $1 notation mean that the value 1 is encoded in the instruction itself (immediate value)? You seem to imply that it is referencing a variable somewhere else in memory.