I have a very extrange problem with calloc.
I am working with Dev-C++ in Windows. The code is in C but I compile it as C++. All my files are .cpp
I will explain the situation. I have a program that calculates forces using data files. Each data file corresponds to experimental measures in an instant and from each file you can get the force in this instant.
The program is used to calculate the forces in a lot of instants. Each data file has exactly de same number of doubles ordered in exactly the same way. To solve each file the program does always exactly the same. It is just a loop that reads the files and solves them one after the other.
I found that when I tell the program to calculate the force in the files from 50 to 350 it stops unexpectedly in the file 75. I tryed to run the program to solve the forces between files 51 to 351 and I expected that it stops in file 75 or 76. But it stops in file 253. It means that the file 75 is not corrupted and that it is not a problem of memory that appears after solving a number exact of files.
The file where the error happens depends only on the file where you start to solve the forces. It is always the same. It shows that it is not random. However each file is read and deleted after it is used so it is extrange that the error deppends on the data file where you start the execution.
I looked for the error and it happens in exactly this line of code:
aux=(double *) calloc(lN-l1+1,sizeof(double));
Where lN-l1+1 = 2. This line of code is exectuted exactly with the same arguments for each data file however it fails only with some files.
calloc does not return a null ponter. The program stops when it arrives to this line so you don't have a null pointer. You have nothing.
I checked with the tasks administrator of windows that I have more than enough memory.
Another extrange thing is that when I try to run the debugger it does not run. Only with the first data file, but it stops after that I don't know still exactly in what line.
If I execute the program in a different computer the program stops in a different moment. I still didn't check but probably in a similar line.
The program stops in a different moment when I execute it cliking over the "compile and execute" button of the Dev-C++ environment or when I execute it writing the name of the program in the MSDOS command window.
The results that the program gives while it works are good, even with that files where it stops when you star to solve with certain files.
These are all the things I have tested. I hope somebody can help me. I don't know what else I can try.
Thank you very much