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

Sounds crazy, but Unix does it and we don't bat an eyelid.

  [true.c]
  int main() { return 0; }

  [false.c]
  int main() { return 1; }


Why?!


Because its originally error codes. 0 is "all went well", != 0 is an error code telling you why it failed. I'd guess which then got things added like "programA && programB" as "A went well, so do B and check if B goes well", which kinda gives the logic value true to 0.


Right, should have remembered that from that time I got into C...


Although C does map 0 to false, so it really is a shell-ism, despite the return code pattern being used in C and other places.




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

Search: