4 ms·
… but they'd also leave off the "inline" and use "int" instead of bool. Why use int, when there's bool in C99 that clearly communicates the intent?
by xyzzyz 14y ago
… but they'd also leave off the "inline" and use "int" instead of bool.
Why use int, when there's bool in C99 that clearly communicates the intent?
- zvrba 14y agoBecause 1) bool is a useless type in C and C++ since it's an arithmetic type, 2) it's no clearer than an int. (consider a function that returns true on failure, logic being that the rest of the program should be aborted.) You expect that "true" is success, but you can't know without checking, and then you're back in the same situation as with int. In practice, idiomatically, you write something like if(!some_function(blah)), and in this context it totally doesn't matter whether the function returns bool or int.
- jws 14y agoI like the human communication aspect of "bool", but dislike the compiler language dependency. The C cultural expectation is that anything named like a predicate is going to return an int for true or false. In another language with a different culture I would use a Boolean or whatever it had.
- xyzzyz 14y agoEvery modern C compiler (not counting Microsoft one with terribly lame support for C99) supports bool, so there's no compiler dependency.