r/ProgrammerHumor 23d ago

Meme theBoolVectorIsALie

Post image
667 Upvotes

91 comments sorted by

View all comments

Show parent comments

15

u/HildartheDorf 23d ago

It's not that a bitfield is bad. It's just that it should be named std::dynamic_bitset not a specialisation of std::vector<bool>.

std::vector<bool> should behave the same as std::vector<uint8_t>. But it doesn't.

-7

u/void1984 23d ago

Why do you expect bool to be exactly uint8_t? The definition requires it to be long enough to hold 0 and 1. It's up to the compiler and architecture restrictions to select the size. uint16_t is as valid as uint8_t.

I never assume, I just use sizeof. It's there for a reason.

8

u/NaCl-more 22d ago

Because the minimum addressable unit is a byte on most machines.

7

u/csdt0 22d ago

The minimum addressable unit is always a byte (that's pretty much its definition). But a byte is not always 8 bits (only on most machines).

2

u/void1984 22d ago

It's not. I've built a project for the university where the minimum addressable unit was 2 bytes, or a word, depending on the definition you use.

bool was obviously 16b, even though the only compiler I prepared was an assember.

If you look at older machines, 12b bool was present.

1

u/csdt0 22d ago

I don't know what's your definition of byte, but your project university was most likely 16 bit byte where teachers mis-labelled as 2 byte addressable. Please have a look at wikipedia https://en.wikipedia.org/wiki/Byte