Return value(s) from functions - any defacto standard?
- From: Jimbo_Jimbob_Jiminator <JimboJimbobJiminator@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 5 Dec 2008 05:42:07 -0800
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
.
- Follow-Ups:
- Re: Return value(s) from functions - any defacto standard?
- From: Doug Harrison [MVP]
- Re: Return value(s) from functions - any defacto standard?
- Prev by Date: Re: SS_RIGHT and SS_OWNERDRAW
- Next by Date: Re: syntax error in VS2005
- Previous by thread: CDC::SelectObject
- Next by thread: Re: Return value(s) from functions - any defacto standard?
- Index(es):
Relevant Pages
|