Saturday, July 12, 2008

Going back to basic – should 0 or 1 be returned from function..

Here is a very good article about this topic.

The basics concern whether you should return 0 as success or 1 as success. In a main function , normally, you will return 0 as success and other variables as failure codes. However, when you try to map to boolean code, 0 is false, and non-0 is success, and that’s the extra level of confusion. So, if you do want to return boolean state as the function return value, it’s best to use bool, NOT integer.

No comments: