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

Iff in your language of choice a Boolean is always converted to a 1 or 0. In C, at least, that's not necessarily the case.

That said, I'm always looking for the least branchy way of doing things.



I was under the impression that the C standard does mandate that comparisons give 1 and 0 for true and false. (Other nonzero things are considered true, but a plain comparison won't return them.)


It does.

ISO/IEC 9899:1999, 6.5.8, p6 has this to say:

"Each of the operators < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to) shall yield 1 if the specified relation is true and 0 if it is false. The result has type int."




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: