4 ms·
Nope. Having '1' as the condition in the ternary operator, causes 'var' to never be evaluated (to avoid accidental operations with getters and such), but the co
by JoeCortopassi 14y ago
Nope. Having '1' as the condition in the ternary operator, causes 'var' to never be evaluated (to avoid accidental operations with getters and such), but the compiler allows the 'var' to affect if the '1' is treated as a float or an int. Here's a breakdown:
if var is a float...
(1?1:var)/2
...becomes...
(1.0/2)
...which equals 0.5 and is considered true when evaluated. But if var is an int...
(1?1:var)/2
...becomes...
(1/2)
...which equals 0 and is considered false when evaluated
- Groxx 14y agoIs that part of the spec for coercions, or is it exploiting a typical compiler's behavior? It certainly doesn't appear to be a required way to process that statement (optimizations could remove the 'if' portion entirely), unless it is actually required of the compiler.