News for hackers. Stuff that matters.
Re:Show HN: My weekend project - Codestagram by JoeCortopassi on Wednesday January 02, 2013 @04:58PM (#4999558)
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
Re:Show HN: My weekend project - Codestagram by Groxx on Friday January 04, 2013 @12:01AM (#5006345)
Is 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.