I am wondering if the C++ standard guarantees that multidimensional arrays (not dynamically allocated) are flattened into a 1D array of exactly the same space. For example, if I have
char x[100];
char y[10][10];
Would these both be equivalent? I'm aware that most compilers would flatten y
, but is this actually guaranteed to happen? Reading section 11.3.4 Arrays of the C++ Standard, I cannot actually find anywhere that guarantees this.
The C++ standard guarantees that y[i]
follows immediately after y[i-1]
. Since y[i-1]
is 10 characters long, then, logically speaking, y[i]
should take place 10 characters later in memory; however, could a compiler pad y[i-1]
with extra characters to keep y[i]
aligned?