H
hpsMouse
This problem has confused me for a long time. Think about the following simple declaration:
char arr[3][4][5];
Will arr[j][k] always be equivalent to *(&arr[0][0][0] + i * 4 * 5 + j *5 + k) ?
All the books I read says it's true. But when I turn to ISO C++98/03 I don't find enough clue about it.
The only paragraph I found about this topic is 8.3.4/1, in which it says:
An object of array type contains a contiguously allocated non-empty set of N sub-objects of type T.
It means there shall be no padding between two elements in the same array. However it didn't say whether there can be any padding bytes at the end. Ifa tailing padding exists, sizeof(char[5]) may be greater than 5, and the method to locate arr[j][k] may be incorrect.
Did I miss anything, or the standard just said nothing about such a padding?
char arr[3][4][5];
Will arr[j][k] always be equivalent to *(&arr[0][0][0] + i * 4 * 5 + j *5 + k) ?
All the books I read says it's true. But when I turn to ISO C++98/03 I don't find enough clue about it.
The only paragraph I found about this topic is 8.3.4/1, in which it says:
An object of array type contains a contiguously allocated non-empty set of N sub-objects of type T.
It means there shall be no padding between two elements in the same array. However it didn't say whether there can be any padding bytes at the end. Ifa tailing padding exists, sizeof(char[5]) may be greater than 5, and the method to locate arr[j][k] may be incorrect.
Did I miss anything, or the standard just said nothing about such a padding?