title: Abort error in C program when it reaches the end
body: <p>I'm writing an orbit propagator in C, all the calculations work properly but the end is reached it suddenly aborts unexpectedly.</p>
  
  <pre><code>[1]    67117 abort
  </code></pre>
  
  <p>I tried to use Valgrind (which is only experimental on Mac, I know) to spot my error(s) and the final error it outputs is the following :</p>
  
  <pre><code>==67127== Process terminating with default action of signal 4 (SIGILL)
  ==67127==  Illegal opcode at address 0x1A6BDA
  ==67127==    at 0x1A6BDA: __abort (in /usr/lib/system/libsystem_c.dylib)
  ==67127==    by 0x1A746C: __stack_chk_fail (in /usr/lib/system/libsystem_c.dylib)
  ==67127==    by 0x1000019FD: main (call.c:188)
  [1]    67127 illegal hardware instruction
  </code></pre>
  
  <p>call.c is the script in which there is my main function and its 188th line is the final } all by itself as follows :</p>
  
  <pre><code>    return 0;
  }
  </code></pre>
  
  <p>I wrote the same program in matlab before and it works perfectly but to translate it to C I had to use pointers which may be the cause of my error but Valgrind's report doesn't say so :</p>
  
  <pre><code>==67256== LEAK SUMMARY:
  ==67256==    definitely lost: 0 bytes in 0 blocks
  ==67256==    indirectly lost: 0 bytes in 0 blocks
  ==67256==      possibly lost: 0 bytes in 0 blocks
  </code></pre>
  
  <p>However it claims I have 10 mio errors of "use of unitialised value" (that I checked using Xcode and corrected for those Xcode pointed.)</p>
  
  <pre><code>==67256== ERROR SUMMARY: 10000000 errors from 185 contexts
  </code></pre>
  
  <p>But most of them either point to the standard library or to values that will be initialised in other functions whose role is to initialise them (using pointers). Could this be the cause of this error ? As the propagation works just fine until it reaches the end (I can print the values for each time step in the terminal using printf) and just ends up aborting I didn't think so.</p>
  
  <p>When I run it using Xcode it just never stops running and never writes the files I asked it to with the different values at each time step. (However when I use Valgrind it does).</p>
  
  <p>I don't usually use Xcode but I thought I would this one time, is there any compiler settings that could help me spot the error or does anyone have any idea what I might have done wrong ?</p>
  
  <p>EDIT :
  I just want to add the last instructions in my main function which are the following. Everything works fine, then I reach the following while loop :</p>
  
  <pre><code>    while ((tsince &lt; stopmfe) &amp;&amp; (satrec.error == 0))
  </code></pre>
  
  <p>in which everything works fine too (according to the files that were printed using Valgrind) until it reaches the end of it,
  then I only have the fclose instructions as follows :</p>
  
  <pre><code>    fclose (outfilee);
      fclose (infile);
      fclose (outfile);
  return 0;
  }
  </code></pre>