Jeronimo Pellegrini wrote:
There's another problem with the above C++ code: If ny and nz aren't constant, you can't write
double s[ny][nz];
Instead, either you allocate the array in two stages:
double** s = new (double*)[ny]; for (j=0; j < ny; ++j) s[j] = new double[nz];
Actually, the first version works -- and both C and C++ (tested here with gcc -- not sure it it became a standard or not)) will dynamically allocate memory for you. Try this:
int size1, size2, i, j; cin >> size1; cin >> size2; double vec[size1][size2];
And enter something like "1000" and "1000" when asked for the array dimensions. It compiles, runs, and does not segfault! :-)
Are you absolutely sure that code is supposed to work?
Your program segfaults on cygwin (using gcc 3.3.1) when using 1000 and 1000. On my sarge installation (gcc 3.3.4) it seems to work when using 1000 and 1000, but segfaults when using 1000 and 10000. Either you were lucky, or it's a feature that's introduced in more recent versions of gcc.
-- "Codito ergo sum" Roel Schroeven
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]