3 ms·
Because if (..) c = 1 else c = 2; will "obviously" map on to a branches whereas c = .. ? 1 : 2; "obviously" corresponds to a cmov. It's a natural ma
by zasdffaa 4y ago
Because
if (..) c = 1 else c = 2;
will "obviously" map on to a branches whereas
c = .. ? 1 : 2;
"obviously" corresponds to a cmov. It's a natural mapping, if not necessarily correct mapping with more knowledge.
- IshKebab 4y agoWhy though? Ternary is always introduced as syntactic sugar for if/else.
- zasdffaa 4y agoMy K&R C book agrees with you, but there when you know about cmov, it seems to map cleanly to ?:. It's just my opinion and what I feel. I can't back it up any better.
- monocasa 4y agoBecause it's an single assignment expression dependent on a result that'll probably trivially be in a status flag.