Array Initialization warnings
bjorn rohde jensen
shamus@tdcadsl.dk
Wed Apr 24 12:09:00 GMT 2002
Hi Sebastian,
The real issue was the syntax of static initialisation
of multidimentional arrays, we just got a little side tracked.
Bjorn
Sebastian Huber wrote:
>
> Hello,
> I think this identity between the dereference operator (is this the English
> translation?) and access via pointers is helpful:
>
> T a [S_1][S_2]...[S_N];
>
> a [i_1][i_2]...[i_n] <=> a
> + i_1 * S_2 * ... * S_N_MINUS_1
> + i_2 * S_3 * ... * S_N_MINUS_1
> + ... +
> + i_n
>
> For example:
>
> #include <iostream>
>
> int main()
> {
> int a [2][2][2][2] = {
> { { { 0, 1 }, { 2, 3} }, { { 4, 5 }, { 6, 7 } } },
> { { { 8, 9 }, { 10, 11} }, { { 12, 13 }, { 14, 15 } } }
> };
> for (int i = 0; i < 16; ++i) {
> cout << *(reinterpret_cast<int*>( a) + i) << endl;
> }
> std::cout << a [1][0][1][0]
> << " == "
> << *(reinterpret_cast<int*>( a) + 1 * 2 * 2 * 2 + 0 * 2 * 2 + 1 * 2 + 0)
> << endl;
> return 0;
> }
>
> Ciao Sebastian
More information about the Gcc-help
mailing list