Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: parameter[][] Message-ID: <376@taumet.com> Date: 3 Aug 90 20:10:29 GMT References: <1545@m1.cs.man.ac.uk> Organization: Taumetric Corporation, San Diego Lines: 29 jk@cs.man.ac.uk (John Kewley ICL) writes: >One of our staff is whingeing about having to specify the size of all >dimensions for a multidimensional array (beyond the first that is). >Can anyone give me some good reasons why this is, so I can placate him. >He claims that it can be done in C so why can't it be done in C++. It can't be done in C either, and you should get him to put up or shut up (that's American for "prove it's true or stop whingeing", whatever "whingeing" may be). This is specified in every C text I've ever seen, including K&R 1, section 5.7. ANSI C also requires it. A specific example: If you declare T x[n][m]; it means x is an array of n elements, each of which is an array of m elements of type T. When you then say j = x[i][j]; the compiler knows that each row contains an array of m elements, so it multiplies m*sizeof(T) to get the size of each row in the array, multiplies that by i to get the offset of the row, and then adds j*sizeof(T) to get the final offset. If you do not declare the value of m, how do you find the start of any row beyond the 0th row? You can't. -- Steve Clamage, TauMetric Corp, steve@taumet.com -- Steve Clamage, TauMetric Corp, steve@taumet.com