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 eldritch horror. Without a pragma I would not put money on doing horrible things to a structure such as being certain where an item was.

If forced, well I'm a bit rusty, but I'd probably do something truly icky with pointers at known offsets. Possibly even something nasty and uniony.

Or not do that to a structure, cause you're not meant to!

@syllopsium Memory exists. Many programmers wish to pretend that memory does not exist. But memory exists

@mcc oh, absolutely. One of my many in progress projects involves directly bit twiddling an Intel .hex file, which straight away requires fiddling with pointers and knowing what endian a platform is.

It's not using structures against the bytestream though :)