[openbeos] Re: B_TRUE/B_FALSE

  • From: "Jonas Sundstrom" <kirilla@xxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Sun, 21 Sep 2003 14:52:24 +0200 CEST

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'd have to check for status < 0,  since B_OK would clash with 
B_FALSE,

You'd want to catch all errors, so you can't do an if (status == 
B_ERROR).
(B_ERROR is -1, IIRC.) You'd miss the range of explicit error 
conditions.

One could of course pick numbers that don't clash with B_OK. 

#define B_FALSE 9
#define B_TRUE 10

Or keep true/false as they are, to avoid confusion and mistakes, 
and introduce a non-zero B_BOOLEAN_OK, or something.

Or use reference paraments like you, and Ingo, said.

(Isn't it unusual for a boolean function to fail, I mean, it's either 
true or false..
 Perhaps it shouldn't have been a boolean in the first place?)

/Jonas Sundström.                          www.kirilla.com


Other related posts: