[openbeos] Re: B_TRUE/B_FALSE

  • From: Ingo Weinhold <bonefish@xxxxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 21 Sep 2003 14:11:50 +0200

On 2003-09-21 at 14:01:36 [+0200], Jonas Sundstrom wrote:
> Tyler Dauwalder <tyler@xxxxxxxxxxxxx> wrote:
>  ...
> > Another option is then to use a boolean output parameter and return a
> > status_t instead, but output parameters are just annoying.
>  ...
> > #define B_FALSE 0
> > #define B_TRUE 1
> > 
> > then, one could just return a status_t for the function, check for "<
> >  B_OK"
> > to see if an error occurred (yielding a hopefully useful error code
> > if so),
> > and if not, check against B_TRUE or B_FALSE to see what the result of
> > the
> > function was.
> > 
> > You could also define a bool_t or a boolstatus_t type that's
> > identical to
> > status_t, but whose use as a return value would flag the function as
> > operating as described above instead of just returning a standard
> > status_t.
> > 
> > Thoughts?
> 
> Are you saying you'd prefer something other than the current
> way of returning status_t and if (status != B_OK)
> check the error code if it's B_ERROR_X, B_ERROR_Y, ..
> or prinft("Error: %s\n", strerror(status));
> 
> What problem are you trying to solve?

He's trying to solve the same problem for boolean return values, that 
ssize_t solves for non-negative integers, i.e. that you can return both, an 
actual value, if everything went fine, or an error code otherwise.

Though, now that I think of it, I never liked this return value/error code 
multiplexing. The IMHO straight forward way is to return a status_t and 
pass the data back through a reference parameter. This is more flexible 
anyway, since it works for any data type.

CU, Ingo

Other related posts: