title: Windows popup: X.exe has stopped working (Code::Blocks)
body: <p>thanks in advance for taking a look at this.</p>
  
  <p>I'm getting a Windows error message when I try to run this program I wrote in C in Code::Blocks. The funny thing is it compiles fine, and if I lower the upper bound of what I'm testing the program runs fine as well. </p>
  
  <p>Details:</p>
  
  <p>When I try to run the program, first I get a Windows popup that says "X.exe has stopped working. Windows is checking for a solution to the problem". Shortly this changes to "X.exe has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. (Close program)" I click the close program button, and then I see the command prompt that says "Process returned 255 &lt;0xFF>  execution time 3.940 s  Press any key to continue". </p>
  
  <p>I have Windows 8.</p>
  
  <p>I'm using the GNU GCC compiler. </p>
  
  <p>If I change "upto" to 100000, the program works fine. </p>
  
  <p>Here's the code:</p>
  
  <pre><code>/************************************************
  * Finds the starting integer under 1000000 that
  * produces the longest Collatz sequence, and the
  * length of said sequence.
  *************************************************/
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;limits.h&gt;
  #define upto 1000000
  
  int main()
  {
      long i;
      long long j;
      long long max = LONG_LONG_MAX;
      long length = 0;
      long number = 0;
      long penull = 0;
      long len[upto];
      for (i = 0; i &lt; upto; i++) (len[i] = 0);
      // counts length of Collatz sequence for starting integers from 1 to 999999
      for (i = 1; i &lt; upto; i++)
      {
          j = i;
          while (j != 1)
          {
              assert (j &lt;= (max - 1)/3);
              if (j%2 == 0) (j = j/2);
              else (j = 3*j + 1);
              len[i]++;
              if (j &lt; i)
              {
                  len[i] = len[i] + len[j];
                  j = 1;
              }
          }
          // stores length of the longest sequence and the starting integer producing it
          if (len[i] &gt; length)
              {
                  length = len[i];
                  number = i;
              }
          // stores a duplicate length for later comparison
          else if (len[i] == length) (penull = len[i]);
      }
      if (length == penull) (printf("There are at least two!"));
      else printf("%ld produces a Collatz sequence of length %ld", number, length + 1);
      return 0;
  }
  </code></pre>