Roel Schroeven <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > Jeronimo Pellegrini wrote: [...] > > 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.
There is a posibility that you run out of stackspace. I guess these dynamically sized arrays are allocated on the stack. You might want to try setting the stacksize to "unlimited". I've found that gcc has implemented this at least for seven years or so. If I remember correctly I found a news article in the google groups dated in 1996 which mentions this feature of gcc. Also, I found that the C99 standard incorporated this feature: http://home.tiscalinet.ch/t_wolf/tw/c/c9x_changes.html It's interesting that some of the new features are (or seem to me to be) mainly for numerical computations, such as the "restrict" keyword and the builtin complex numbers. I suspect they are influenced by Fortran. And it's amusing to see that C99 has *at last* caught up with Fortran 77 (partly with Fortran 90/95) in terms of dynamically sized multidimensional arrays, complex arithmetics, and "restrict"ed pointers, although C99 lags far behind Fortran 90/95 in terms of intrinsic array operations. ;-) Cheers, Ryo -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]