Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

And in C we can do this to get TRUE:

    return (33 == '3');
:P


Incorrect. However, (0x33 == '3') will return true, as will (51 == '3'). Your point is valid, even if your code is wrong. Automatic type coercion can produce unexpected results in any language.

PHP's automatic type coercion rules are designed to help newbies at the expense of experienced developers. C's automatic type coercion rules are, largely, designed to expose the underlying memory layout to developers who know what they're doing, at the expense of inexperienced developers. Both can easily contain dangerous pitfalls, but I prefer the latter philosophy over the former.

(Disclaimer: I have built a career as a C programmer and frequently use its lower-level features to great advantage. I am biased.)


And there are no type-coercion rules at play in case of 51 == '3', because type of '3' is int (as per ISO 9899 p. 6.4.4.3.2).


Excellent point. Thank you for the clarification. This is true in c99 as well.


Okay, I stand completely corrected.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: