From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19523 invoked by alias); 24 Apr 2002 16:58:20 -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 19505 invoked from network); 24 Apr 2002 16:58:18 -0000 Received: from unknown (HELO smtp.web.de) (217.72.192.151) by sources.redhat.com with SMTP; 24 Apr 2002 16:58:18 -0000 Received: from [213.6.63.179] (helo=there) by smtp.web.de with smtp (WEB.DE(Exim) 4.44 #50) id 170Q5w-00048L-00 for gcc-help@gcc.gnu.org; Wed, 24 Apr 2002 18:58:16 +0200 Content-Type: text/plain; charset="iso-8859-1" From: Sebastian Huber To: gcc-help@gcc.gnu.org Subject: Re: Array Initialization warnings Date: Wed, 24 Apr 2002 11:09:00 -0000 References: <3CC17386.5040608@keyed-upsoftware.com> <20020420155818.3c8ca837.liptak@isdd.sk> <3CC17545.E3E68FDE@tdcadsl.dk> In-Reply-To: <3CC17545.E3E68FDE@tdcadsl.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: X-SW-Source: 2002-04/txt/msg00259.txt.bz2 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 On Saturday 20 April 2002 16:03, you wrote: > Hi guys, > > Michal Liptak wrote: > > I think the internal representation of int[4][4] is the same as int[16] > > m. > > That is usually the case, i would think, but i am not sure, it > is required by the standard, so i would not rely on that. > > bjorn