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 In C, sizeof(bool) == 1, but in C++ sizeof(bool) == sizeof(int). b is required to be either at least sizeof(char) or sizeof(int) beyond a. So you don’t know where b is. Compilers will add padding in the absence of pragma pack, which means b is probably 4 bytes beyond a.
On a little-endian machine, reading a as 32-bit at struct+4 will give a different result to reading a as 8-bit at struct+7, whereas it would give the same result on a big-endian machine. So you don’t know where a is either.
@criffer @mcc `sizeof(bool)` is not equivalent to `sizeof(int)` in general, nor is it expected to ever be 4 bytes unless you're on a *really* weird platform.

@dotstdy @mcc You're right, it's not standardised at all. And Windows is a really weird platform.

"bool — integer type, capable of holding one of the two values: true or false. The value of sizeof(bool) is implementation defined and might differ from 1"

https://en.cppreference.com/w/cpp/language/types.html

Fundamental types - cppreference.com

@criffer Windows is not that weird though. It's 1 there too. :') You might be confused by the old `BOOL` type in win32 headers, which is indeed 32 bits.