From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25967 invoked by alias); 24 Apr 2002 18:54:56 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 25925 invoked from network); 24 Apr 2002 18:54:53 -0000 Received: from unknown (HELO fepC.post.tele.dk) (195.41.46.147) by sources.redhat.com with SMTP; 24 Apr 2002 18:54:53 -0000 Received: from tdcadsl.dk ([80.62.84.198]) by fepC.post.tele.dk (InterMail vM.4.01.03.23 201-229-121-123-20010418) with ESMTP id <20020424185452.OXUK11508.fepC.post.tele.dk@tdcadsl.dk> for ; Wed, 24 Apr 2002 20:54:52 +0200 Message-ID: <3CC6FEC2.B4017D7B@tdcadsl.dk> Date: Wed, 24 Apr 2002 12:09:00 -0000 From: bjorn rohde jensen Reply-To: shamus@tdcadsl.dk X-Accept-Language: en MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Re: Array Initialization warnings References: <3CC17386.5040608@keyed-upsoftware.com> <20020420155818.3c8ca837.liptak@isdd.sk> <3CC17545.E3E68FDE@tdcadsl.dk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-04/txt/msg00261.txt.bz2 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 > > 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( a) + i) << endl; > } > std::cout << a [1][0][1][0] > << " == " > << *(reinterpret_cast( a) + 1 * 2 * 2 * 2 + 0 * 2 * 2 + 1 * 2 + 0) > << endl; > return 0; > } > > Ciao Sebastian