self@BAYES.ARC.NASA.GOV (Matthew Self) (10/08/88)
After converting my latest program to use dynamic arrays, I tried running it on some very large data sets to see how it would break. Unfortunately, it appears that if there is insufficient space to allocate a dynamic array, the program just dumps core with no explanation. My previous code which did all of the dynamic allocation through malloc would explain that malloc refused the program the space it wanted, and would even mention which array couldn't be allocated. It would be nice if programs compiled with gcc using dynamic arrays did something along these lines. An even more difficult problem arises if the program can work around the lack of space problem and wishes to continue execution some other way. Perhaps in this case the program just shouldn't use dynamic arrays and should call an allocation routine explicitly. The only other solutions would seem to require adding new extensions to c, which should probably be avoided. I haven't yet looked at the source to see how any of this might be done. A penny for your thoughts.... Matthew Self NASA Ames Research Center self@bayes.arc.nasa.gov
rms@WHEATIES.AI.MIT.EDU (Richard Stallman) (10/08/88)
This problem is not limited to dynamic arrays or to GNU C. The same bad error message can result from allocating a fixed-size array, in any C compiler. You can make your program work by using the command `unlimit stack' first. As for the general problem, I agree the current situation is not a desirable one, but I don't see a solution in the compiler. In the GNU system I think I can see how to arrange for better error reporting for stack overflow, which would distinguish it from stray references. But this requires the compiler and library to cooperate.