>>10,11I mostly agree with Linus on
bools (see
https://lkml.org/lkml/2013/8/31/138 and ), in that they aren't strictly defined enough for a programmer to use them better than `This is a
char or maybe an
int depending on how my compiler feels. It is probably zero or nonzero,' and you don't really get any benefit (in packing in
structs, for example) that a compiler can't also give to a sanely-used integer type.
In addition, I've never really seen a situation in which I wanted to use
bool in which there was a downside to using
char or even
int instead, because in the place I wanted to use the variable, it was always possible for me to tack on more information like an error code, or some useful metric that divided all inputs into two partitions, etc. That's just my experience, and possibly there exists an example that would make me change my mind, but I doubt it.
I would normally give weight to your clarity argument, but the following compiles for me just fine ([m]gcc -o a a.c -std=c99 -Wall -Werror[/m]):
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
bool t, u;
t = 2;
u = t - 2;
if (u) printf("meh\n");
return 0;
}
and outputs
meh
I know perfectly well why it does so, and I won't say that this program is somehow
wrong, but I believe it underscores that in a language like C,
bool doesn't really help the programmer avoid performing numerical operations on the values.
But really, the reason I picked on
stdbool.h specifically is that a lot of C programmers (like Linus) point to it as proof of C++'s insidious influence upon C.