r/ProgrammerHumor • • Oct 07 '26

Meme wasteOfPreciousSpace

Post image
7.3k Upvotes

244 comments sorted by

View all comments

Show parent comment

13

u/Dry-War7589 Oct 07 '26

Yes but no. A bool is a single bit, but a single bit isnt addressable, so you use a byte, which is addressible

3

u/MattieShoes Oct 07 '26

Not necessarily 1 byte. Like some windows BOOLs are (were?) typedef to int, so probably 4 or 8 bytes. And Python built bools on their arbitrary precision int type, so they're... some weird size, and the size is different for True and False

... but yeah, usually 1 byte.

1

u/prehensilemullet Oct 07 '26

Lol wow.  Also TIL that float arithmetic is faster than integer arithmetic in Python, since ints are arbitrary precision…hilarious

1

u/DearVeggies Oct 08 '26

Sounds reasonable for Python, they'd use BigInts as default. Remember, they don't care about performance (and that is good).

2

u/generally_unsuitable Oct 08 '26

Unfortunately, it doesn't work like that in any languages I use. If you set any bit in a boolean's byte, the boolean is now true. This is why you often see crazy shit like:

bool a = !(!(b))

to guarantee that there's either a 1 or a 0 in the boolean.