Follow

why do bit operations on bool return an int? doesn't that defeat the whole point of bool? do I have to redefine every single fundamental type to not be insane?!

@namark C doesn't didn't have bools, so to keep compatibility there's loose casting around those operations.
That's why you use &&, ||, != instead of &, | and ^.
Which guarantee bool.

@pleb it's not casting in this case, it's promotion. how does promoting bool & bool to an int help compatibility with C? In fact because of the implicit casts you don't need to promote.

I want to pass bools to a generic function that uses logical bit operation and get back a bool, instead I get back an int for no reason. A freaking int not even unsigned, and until c++20 it's implementation defined what happens to a signed integer when you bit twiddle it.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.