I'm writing C++. I have a struct

struct ExampleStruct {
int32_t i;
bool a;
bool b;
}

I know I'm running on a modern CPU such as x86_64 or ARM64, and I know I'm using a modern compiler such as recent clang, recent gcc, or recent msvc.

The byte offsets of "a" and "b", relative to the start of ExampleStruct, are:

4 and 5
30.2%
4 and 8
16.3%
It depends on platform/compiler
44.1%
U gotta use a #pragma
9.4%
Poll ended at .
@mcc
I haven't seen anyone respond with this, but since bool could technically be represented in one bit, could the answer be 4 and 4 in any circumstance? (as in the compiler transparently handling bit math on access of the vars in question)
@fxchip @mcc I don't believe so, since it would break unique addressability for individual fields. I *think* you need to explicitly opt-in to that with a bitfield, but I don't know the exact C++ law there. edit: In C++20 I guess if you annotated the field with `[[no_unique_address]]` the compiler would be allowed to merge them into a single byte as well.
@dotstdy
Ah, you know what, that makes sense. I kinda just figured compiled language could just be a lawless land like what I just described. I'm sure it is in other ways but at least this one seems okay 😂
@mcc