Hottejonas wrote:
Quote:
I have written a program in which I declare a double array as follows
double *uMatrix;
>
uMatrix = new double[Nnodes*(Ntimesteps+1)];
>
And I make sure to free it in the last part of the main program
>
delete[] uMatrix;
>
This is the second last statement of the program, and no error occures if I
terminate with exit(0) just after this line. But if I terminate the program
with
>
return 0;
>
instead of the exit(0) statement, I get a segmentation error.
>
>
>
It really puzzles me. Hope you can give me a good answer
Do you have destructors in your code? If so, they are executed
upon "return 0", but not upon "exit(0)" (I think). Therefore
destructors of global and static variables would be the first
suspect to investigate.
If you don't have them, then I'd blame an out-of-bounds
error somewhere -- use a tool like efence or valgrind to
track it, or better still, follow Thomas's advice and
prefer std::vector to dummy arrays.
HTH,
- J.