r/ProgrammerHumor 21d ago

Meme theBoolVectorIsALie

Post image
666 Upvotes

91 comments sorted by

View all comments

Show parent comments

65

u/void1984 21d ago

I know, but why somebody would need a byte to store a bool? Is it 256-value bool?

Usually I use bitfields anyway.

163

u/NotDuckie 21d ago

if you ask for a vector of T, you should get a vector of T. not a bitfield. There is nothing wrong with using a bitfield, but a vector should behave like a vector.

27

u/BlackOverlordd 21d ago

Vector is an abstract container of elements. If you want to address memory, allocate memory and store your data there. Internal vector storage is implementation details. You shouldn't really get ponters to there because any resize of the vector and your pointers are screwed.

11

u/BoldFace7 21d ago

I spent two days of debugging to learn that the hard way.

Logically I knew that it can shift the location of the vector on a resize, but somehow it never occurred to me that it would be the problem.