The C++ standard seems to be a bit laconic about arrays.
Let’s assume that I have two distinct data types: T1 and T2. I create arrays of each of them, with both arrays being of the same length N; so I have T1[N] and T2[N].
Now, does sizeof(T1[N]) == sizeof(T2[N]) imply that the successive elements of both arrays will have the same offsets?
Or, in a more practical form: if I (handling the alignment issues) cast a char[sizeof(T1[N])] both to T1* and to T2*, is it guaranteed that T1[0] and T2[1] will not overlap, and the other way?
Yes.
Arrays do not have any padding or alignment on the ends, and thus
sizeof(T1[N])always equalssizeof(T1) * N.Knowing this, we know that
sizeof(T1[N]) == sizeof(T2[N])impliessizeof(T1) == sizeof(T2)(cancel theNon both sides). Additionally arrays must be contiguous, there is no alignment or padding inside of the array. Thus the answer to your question is yes.