3 ms·
Jesus, can someone unravel that for me?
by nmfisher 6y ago
Jesus, can someone unravel that for me?
- Koshkin 6y agoI can try... In short, this is about how a C compiler is supposed to deduce the type of the ternary operation. So, if x is a constant expression, the compiler figures that the second operand must be NULL (because it is allowed to perform the multiplication, by 0l), whose type then is whatever the third operand says (a pointer to int). The comparison succeeds. Otherwise the compiler does not perform the multiplication, takes the type of the second operand at its “face value”, i.e. as a pointer to void, and converts the type of the third operand to it - which, of course, makes the comparison false in this case.
- esgwpl 6y agoI found a detailed explanation here: https://stackoverflow.com/a/49481218 https://stackoverflow.com/a/49481218