From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: Dynamically declaring 2-d arrays Date: Sat, 14 Feb 1998 12:06:50 -0800 Organization: Alcyone Systems Lines: 33 Message-ID: <34E5F95A.793B45C4@alcyone.com> References: <34DF9744 DOT C7CFDBFE AT ea DOT oac DOT uci DOT edu> <6c3ulo$jq AT freenet-news DOT carleton DOT ca> NNTP-Posting-Host: 165.90.20.242 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Paul Derbyshire wrote: > My dynamic 2D array recipe: > > int (*foo)[ysize] = malloc (xsize*ysize*sizeof(int)); This only wroks if ysize is not a variable, i.e., it is not truly dynamic. gcc has extensions to allow variable-sized arrays, but they are gcc-specific. > As for C++, it ought to be possible (at least with gnu) to use > > foo = new int[y][x]; > /* ... */ > delete [] foo; > > (is it?) Same restriction applies here. In general, it's a bad idea to use any compiler extensions unless you have a _very_ good reason, or know for a fact you'll never have to/want to port the program to another compiler/platform. -- Erik Max Francis, &tSftDotIotE / mailto:max AT alcyone DOT com Alcyone Systems / http://www.alcyone.com/max/ San Jose, California, United States / icbm://+37.20.07/-121.53.38 \ "Life may be / the product of imperfections." / (Marclo Gleiser)