r/ProgrammerHumor • • 10d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

Show parent comment

65

u/Still_Bit_7527 10d ago

Because i asked for a vector of bool, not vector of bits

26

u/geekosas 10d ago

This is the kind of guy that programed Google Chrome XD

15

u/Rainmaker526 10d ago

Then ask for a vector of bytes.

28

u/Still_Bit_7527 10d ago

Bool is a byte. At minimum. All types are min 1 byte, by standard. And sizeof returns integers. Please stop arguing and just accept a common issue. Dont be a contrarian

3

u/geekosas 10d ago

Look a python developer 

13

u/Still_Bit_7527 10d ago

Java*. Compiler can optimize how it wants but documentation and consistency comes first

0

u/[deleted] 10d ago

[removed] — view removed comment

10

u/_killer1869_ 10d ago

A bool, by definition, in just about any language there is, always takes up the amount of space of the lowest addressable memory unit, which is 8 Bit (excluding some special, outdated architectures where you can access single bits directly). C++ is the only language I know of where a data type using bool uses single bits for storing them. Is it more efficient? Yes. But it breaks the universally accepted standard. Consistency is far more important than minimal efficiency improvements. Just add a seperate data type for when you really need that efficiency into the standard library.

5

u/Still_Bit_7527 9d ago

It's even worse. C++ itself actually uses a whole byte for bools. It's only vector that uses bits to optimize when it's a vector of bools

-2

u/geekosas 9d ago

Standard created by Samsung and HK hynx?

Like when pharma diagnosed 50% of kids with ADHD.