[openbeos] Re: B_TRUE/B_FALSE

  • From: Isaac Yonemoto <ityonemo@xxxxxxxxxxxx>
  • To: Tyler Dauwalder <tyler@xxxxxxxxxxxxx>
  • Date: Mon, 22 Sep 2003 13:49:07 -0500 (CDT)

> #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.

In general, it's best to AVOID clashing status_t values with other return
values (its usage all across the DataIO tree -- forcing ssize_t's instead
of just size_t's is a little bit dangerous).  Passing back through errno
might even be a better option.

if you're trying to do:

bool it_worked = SomeFunction();
if (it_worked) DoThis();

would work if various errors were thrown.

I suppose it could be a stand in for:

bool it_didnt_work = SomeFunction();
if (!it_didnt_work) DoThis();

But I think this is kind of awkward.

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.


Other related posts: