Ordering and ordering of bit fields

Is the order of the members in a) in structure b) in the guaruanteed bitfield? In other words, given a specific member of a structure or bit field, am I sure that its offset from the beginning of the structure / bit field will be no less than the sum of the sizes of the members that preceded it?

To give an example:

struct S{
   char a[N];
   unsigned b : M;
   char c : O;  
};

Will the offset c be at least sizeof(a)+sizeof(b)?

+4
source share
1 answer

Yes.

C ++ Standard:

Non-static data members of a (non-single) class declared without an intermediate access specifier are allocated so that later members have higher addresses in the class object.

+3
source

All Articles