title: C initializing a (very) large integer array with values corresponding to index
body: <p>Edit3: Optimized by limiting the initialization of the array to only odd numbers. Thank you @Ronnie !</p>
  
  <p>Edit2: Thank you all, seems as if there's nothing more I can do for this.</p>
  
  <p>Edit: I know Python and Haskell are implemented in other languages and more or less perform the same operation I have bellow, and that the complied C code will beat them out any day. I'm just wondering if standard C (or any libraries) have built-in functions for doing this faster.</p>
  
  <p>I'm implementing a prime sieve in C using Eratosthenes' algorithm and need to initialize an integer array of arbitrary size <i>n</i> from 0 to <i>n</i>. I know that in Python you could do:</p>
  
  <pre><code>integer_array = range(n)
  </code></pre>
  
  <p>and that's it. Or in Haskell:</p>
  
  <pre><code>integer_array = [1..n]
  </code></pre>
  
  <p>However, I can't seem to find an analogous method implemented in C. The solution I've come up with initializes the array and then iterates over it, assigning each value to the index at that point, but it feels incredibly inefficient.</p>
  
  <pre><code>int init_array()
  {
      /* 
      * assigning upper_limit manually in function for now, will expand to take value for
      * upper_limit from the command line later.
      */
      int upper_limit = 100000000;
      int size = floor(upper_limit / 2) + 1;
  
      int *int_array = malloc(sizeof(int) * size);
      // debug macro, basically replaces assert(), disregard.    
      check(int_array != NULL, "Memory allocation error");
  
      int_array[0] = 0;
      int_array[1] = 2;
  
      int i;
  
      for(i = 2; i &lt; size; i++) {
          int_array[i] = (i * 2) - 1;
      }
  
      // checking some arbitrary point in the array to make sure it assigned properly.
      // the value at any index 'i' should equal (i * 2) - 1 for i &gt;= 2
      printf("%d\n", int_array[1000]);  // should equal 1999
      printf("%d\n", int_array[size-1]);  // should equal 99999999
  
      free(int_array);
  
      return 0;
  
  error:
      return -1;
  }
  </code></pre>
  
  <p>Is there a better way to do this? (no, apparently there's not!)</p>