From: "News Reader" Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie: multidimensional arrays problem Date: Thu, 28 Aug 2003 21:15:27 +0200 Organization: UTA/netway (Customer) Lines: 76 Message-ID: References: <87752c88 DOT 0308270034 DOT 646465b AT posting DOT google DOT com> NNTP-Posting-Host: pat-ei.lucent.wellcom.at X-Trace: newsreader1.netway.at 1062098143 10241 195.230.174.18 (28 Aug 2003 19:15:43 GMT) X-Complaints-To: abuse AT uta DOT at NNTP-Posting-Date: 28 Aug 2003 19:15:43 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com You can leave your arrays inside the main() function as long as they are declared static. The following is an example of your program adapted to C (C++ could be arranged accordingly): int main (int argc, char **argv) { int x,y; puts(" currently here\n"); // you won't need this anymore ; ) #define Xmax 1200 // 'const int' does not work with static arrays #define Tmax 51 static double price[Tmax][Xmax+1]; static double reslevel[Tmax][Xmax+1]; // lots of code that doesn't involve price or reslevel // I am just doing something with the arrays here, because ... // ... the optimizer might not generate any code otherwise: for (x=0; x<=Xmax; x++) for (y=0; y wrote in message news:87752c88 DOT 0308270034 DOT 646465b AT posting DOT google DOT com... > I'm quite a novice with c++ so this is probably more a language > issue than a compiler/system one but I've been writing a program > and have just included some multidimensional arrays that make > for a strange effect that I can't explain. > > As the program currently stands it looks i outline like this > > int main() > { > > cout << " currently here\n"; > > const int xmax=1200; > const int tmax=51; > > double price[tmax][xmax+1]; > double reslevel[tmax][xmax+1]; > > // lots of code that doesn't involve price or reslevel > > return 0; > > } > > This compiles and when run doesn't print anything. > If I comment out the two lines dimensioning the multi-dim > arrays, it compiles and runs fine. > If I change the data type of the arrays to int or float, > it compiles OK and runs fine. > > This seems a bit bizarre to me, but as I say, I'm not experienced > with C++. > > Any ideas? > > Many thanks, > Tom