Mail Archives: djgpp/1998/02/14/15:33:12
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)
- Raw text -