afaik data in memory is continuous if i declare e.g a array.
But is it also guaranteed that data. e.g Integers are continuous if they are declared & initialized after each other?
the only guarantee you have is that the addresses of the data members with the same access (all publics, all privates, etc) grow in order of declaration.
However, all sensible compilers will have no padding between those ints, so you can write a static_assert in case your code finds itself somewhere where that is not true
1 2 3 4 5 6 7 8
class MyClass // make sure to update the static_assert after this class definition when making any changes
{
public:
int x;
int y;
int z;
};
static_assert(sizeof(MyClass) == 3*sizeof(int), "does your compiler seriously pad between same-type same-access members?");