r/ProgrammerHumor • • 15d ago

Meme cppAndItsVectorBooleans

Post image
3.4k Upvotes

214 comments sorted by

View all comments

Show parent comment

3

u/Usual_Office_1740 15d ago edited 15d ago

That is what sizeof(bool) outputs. That 1 byte is based on the CHAR_BIT macro which the standard requires is atleast 8 bits. It could also be as much as 32 bits, apparently. Silly C++

4

u/the_horse_gamer 14d ago

this comes from C, which was created at a time where there were processors that used non-8 bit bytes.

there still exist such processors today, used in some niche places.

2

u/KellerKindAs 13d ago

That's the C remnant from a time, where a processor word was not guaranteed to be 8-bit (aligned). Also: CHAR_BIT is atleast 7 bit as a char is required to fit the ASCII table. The 8'th bit is already optional (but guaranteed on all modern systems with 8-bit aligned memory and 32/64 bit cpu words)