[openbeos] Re: B_TRUE/B_FALSE

  • From: Tyler Dauwalder <tyler@xxxxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Mon, 22 Sep 2003 22:48:46 -0700

On 2003-09-22 at 11:49:07 [-0700], Isaac Yonemoto wrote:
> > #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.
> 
> Wouldn't this be confusing? since a lot of code uses:
> 
> status_t error = SomeFunction();
> if (error) DoThis();
> 
> Then a result of B_TRUE would be the same as having an error.

You'd have to use:

if (error < B_OK) DoThis();

[...]
> In general, passing errors is a problem with the C language -- and C++'s
> throw/catch scheme makes multithreading and code reading incredibly
> hard.  The best thing is to pass a status_t * on the stack, if you
> absolutely need to.  All the kernel calls do this.

I think the consensus we've come to is to return a status_t and just get the 
boolean value via a reference output parameter. You could do it vice versa, 
I suppose, but other functions that have structs that are passed in as 
output parameters return the status_t value; you might as well be 
consistent. :-)

-Tyler

Other related posts: