4 ms·
Its only reason for existence is that if-s in C are statements and not expressions. But an if and a ternary expression do the same thing. Making two different c
by yakubin 5y ago
Its only reason for existence is that if-s in C are statements and not expressions. But an if and a ternary expression do the same thing. Making two different constructs to do one thing doesn't sound all that simple to me. And the standard has special treatment for parsing ternary expressions. It basically says that in any "a ? b : c" pretend that "b" is surrounded with parens, so that it's effectively "a ? ( b ) : c". Because specifying a grammar that has clear precedence was too hard.
- dnautics 5y agoOk thanks for explaining that to me, I understand and agree. For the most part I was just thinking ?: When you need an expr, which by itself is not the worst (though an expr-if , like in zig, or basically any functional pl, is much better). But I wasn't aware of the other issues.