The idea in returning 0 on success and a non-zero value in case of failure is of course that if the program succeeds we generally aren't interested in why, whereas with a failure it's nice to know why.

So a program can return 1 for running out of memory, 2 for pointer error, 3 for .. etc. That way you can check if there is an error by looking at if the value is zero or non-zero, and if you need to know more about what caused the error you can look at the actual value returned .

The C standard defines two macros, EXIT_SUCCESS and EXIT_FAILURE, which can be used as appropriate return values to the operating system. They are respectively 0 and 1.

...The C standard defines two macros, EXIT_SUCCESS and EXIT_FAILURE, which can be used as appropriate return values to the operating system. They are respectively 0 and 1.

I don't sometimes care of what can say the standards...Why ?It's simply psychologic and it has a real explanation :The common 'human' sense would recognize that a 'TRUE' value seems positive, and 'FALSE' the opposite.So what ?I've told to my program to execute this_task and it replied to me that there were NO errors singnaled, so the return is TRUE, else in case of failure it would return 0...And this common human readable/understandable sense can be also found onto 80% of the APIs here and there, where 0 indicates a failure or a NULL return ( example : Findwindow, SleepEx, ... )

The problem with not following the generally accepted standards and conventions is that your program will behave unexpectedly.

If somebody uses your program in a script or makefile they will automatically assume that the return value will be zero on success, so they will be scratching their heads for a while wondering why your program keeps failing until they look at the source and see it.

The problem with not following the generally accepted standards and conventions is that your program will behave unexpectedly.

At first, it seems you did NOT read explanations i gave into my previous post.

Quote

If somebody uses your program in a script or makefile they will automatically assume that the return value will be zero on success, so they will be scratching their heads for a while wondering why your program keeps failing until they look at the source and see it.

Secondly I gave souces also, and if you don't agree with that, feel free to make your own executable.At last, there is no way my code lead into crash or alike, the only two return code are 1 in case of success and 0 in case of failure (generally encountered into API calls)So WTF ?

actually Jibz' explanation was a great one I thought (regarding why anything but 0 is used to represent different error codes).

but regardless, this is just one of those cases where it's silly to go against the standard. return codes can actually be used by other programs and i don't see a good reason not to follow convention. just follow in the good hacker tradition and write a curse-filled paragraph in the readme about how you disagree with the standard, and then implement the standard

actually Jibz' explanation was a great one I thought (regarding why anything but 0 is used to represent different error codes).

but regardless, this is just one of those cases where it's silly to go against the standard. return codes can actually be used by other programs and i don't see a good reason not to follow convention. just follow in the good hacker tradition and write a curse-filled paragraph in the readme about how you disagree with the standard, and then implement the standard

WTF 'standard' ?And when APIs you're using just return 0 as ERROR, how do you consider standard as standard ?There are several programming schools, several point of view, and mine is optimistic + API sided, where 0 means ERROR and 1 or TRUE means OK, that's all folks.

If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned. If the value of status is EXIT_FAILURE, an implementation-defined form of the status unsuccessful termination is returned.

Stroustrup (my K&R is in danish and I didn't want to post a translation .. it says basically the same thing though):

Quote

The int returned by main(), if any, is the program's return value to "the system." If no value is returned, the system will receive a value indicating successful completion. A nonzero value from main() indicates failure.

By convention, a return code of zero means that the program completed successfully.

For most programs it doesn't matter much what value you return, since nobody is ever going to inspect it anyway. But a program like touch is likely to be used in scripts and makefiles, and that's why I feel it's better to have it return the most standard values.