If I have a struct like this:
struct S {
ANY_TYPE a;
ANY_TYPE b;
ANY_TYPE c;
} s;
Can I safely assume that the following assumptions will always be true on all platforms?
((char *)&s.a) < ((char *)&s.c)
((char *)&s.a + sizeof(s.a) + sizeof(s.b)) <= ((char *)&s.c)
In C++ too?
Yes, in C at least. The compiler is free to insert padding after any structure member but it must not reorder the members.
It must also not insert padding before the first member.
From C99,
6.7.2.1: