From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16604 invoked by alias); 30 Sep 2002 21:48:58 -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 16594 invoked from network); 30 Sep 2002 21:48:56 -0000 Received: from unknown (HELO hotmail.com) (64.4.9.18) by sources.redhat.com with SMTP; 30 Sep 2002 21:48:56 -0000 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 30 Sep 2002 14:48:56 -0700 Received: from 143.183.121.3 by lw9fd.law9.hotmail.msn.com with HTTP; Mon, 30 Sep 2002 21:48:56 GMT X-Originating-IP: [143.183.121.3] From: "Jason Mancini" To: gcc-help@gcc.gnu.org Bcc: Subject: RE: How to pass 2D variable-sized arrays in C++? Date: Mon, 30 Sep 2002 14:48:00 -0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 30 Sep 2002 21:48:56.0635 (UTC) FILETIME=[2D3BF8B0:01C268CB] X-SW-Source: 2002-09/txt/msg00233.txt.bz2 Hi again, After many tries, I propose that this is the "correct solution". The compiler should hide the address calculation for me -- this is why we have compilers after all! Thanks, Jason Mancini void func(int c, int r, float *fa) { float (*f)[c] = (float (*)[c])fa; ... f[xr][xc] ... } main() { int c = 5, r = 4; float f[r][c]; func(c, r, &f[0][0]); } ------------------------------- Claudio Bley wrote: The second problem is that it might not do what you expect when you want to use it in the usual notation f[i][j] which is actually equivalent to (*(*(f+i)+j)). The correct solution is to use it like so: void print_mn (int m, int n, float *f) { for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { cout << f[i*n+j] << '\t'; } cout << endl; } } float[4][5] f; print_mn (4, 5, &f[0][0]); _________________________________________________________________ Send and receive Hotmail on your mobile device: http://mobile.msn.com