Return value(s) from functions - any defacto standard?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am curious to know if there is a guideline or defacto standard for return
values that indicate success and fail. I am working with an SDK that, on
success, returns 0 for some calls and returns 1 on others. In fact, some
return -1 for fail.

In C++, MFC, etc. some calls will return a 1 or 0 and then you use get last
error or something similar to get more info. However, for most user written
code I don't see that so much.

Historically, in the embedded, non-windows world, my thought process was
there is usually only one way it can go right and many ways it can go wrong.
Therefore, I usually used 0 for success and then -1 thru -n for various
failure indicators. I have to admit though, that I am not always consistent.
I have posed this question to a few programmers at work and gotten mixed
results and some dis-interest.

Functions that return an expected value are of course not really a problem.
Like atof(), you get a float back. CString.Left() you get a CString. I
suppose if you want to mix in failure mode codes as returns from these
functions it could get complicated, but I don't think they support failure
codes.

I figured I would pose this question to the wider newsgroup audience to get
a well-rounded answer.

Regards,
Jim


.



Relevant Pages

  • Re: A simple parser
    ... success, EXIT_FAILURE for failure. ... indicate *success* to the calling environment. ... It's often possible to define return values other than the standard ... Other error codes could be syntax error in ...
    (comp.lang.c)
  • Re: 20 Years of JPEG Celebrated With Software Launch
    ... I have nothing against commercial success, ... what the marketing claims. ... So that is why you will fail, and I only point it out to ... Otherwise you will be doomed to failure. ...
    (comp.compression)
  • Re: oooppps I forgot (repost from Dawn)
    ... I also forgot to post my meter. ... I will not fail. ... Success comes to those who make it happen, not those who let it happen. ... Failure is the path of least persistence. ...
    (alt.support.stop-smoking)
  • Re: Return value(s) from functions - any defacto standard?
    ... values that indicate success and fail. ... success, returns 0 for some calls and returns 1 on others. ... suppose if you want to mix in failure mode codes as returns from these ... report error codes some other way. ...
    (microsoft.public.vc.mfc)
  • Re: Test Driven Development
    ... >> by definition, going to fail. ... If your test went from failure to success, ... > from success to success, ... manner frighens, or is some people. ...
    (comp.object)