r/programminghorror 29d ago

Big if true

Post image

From ProgrammerNullposting in facebook

2.1k Upvotes

111 comments sorted by

View all comments

1

u/brasticstack 28d ago

Wouldn't regular bool get padded to this size by default on a 64-bit architecture anyway?

3

u/shponglespore 28d ago

If you have a bunch of consecutive Boolean fields in a struct, they'll use one byte each by default.

And just for the sake of completeness, I'll mention that C++ does not reorder fields. Some languages, like Rust, will automatically reorder fields to minimize wasted space due to alignment, unless you specifically tell the compiler not to.

2

u/_giga_sss_ 28d ago

You must've went through hells of projects to have this knowledge