title: Stack overflow exception before entering main()
body: <p>when compiling (and executing) this c++ -code with vs2010, I get a stack overflow exception just before it could even write a glimpse of "Start" to the console.</p>
  
  <p>All the header-files that I use are included in stdafx.h, but that's obviously not the problem here (same problem when including the header-files directly).</p>
  
  <p>Stack trace is the following:</p>
  
  <pre><code>&gt;   msvcr100d.dll!__set_flsgetvalue()  Zeile 145 + 0xc Bytes    C
      msvcr100d.dll!_getptd_noexit()  Zeile 500   C
      msvcr100d.dll!_getptd()  Zeile 523 + 0x5 Bytes  C
      msvcr100d.dll!_LocaleUpdate::_LocaleUpdate(localeinfo_struct * plocinfo)  Zeile 243 + 0x5 Bytes C++
      003efe3c()  
      TerrainGenerator.exe!pre_cpp_init()  Zeile 298 + 0x21 Bytes C
  </code></pre>
  
  <p>Any help would be greatly appreciated, I'm an absolute beginner in c++, as you may see in the code-style, I tried exactly EVERYTHING to get rid of this annoying problem, such as not even declaring ONE additional function and so on... Please help me, and don't hesitate to ask if you need additional info.
  Thanks in advance.</p>
  
  <pre><code>#include "stdafx.h"
  
  int main(int argc, char* argv[])
  {
      puts("Start");
  
      const int res = 4096;
      srand(time(NULL));
  
      uint16_t data[(res+1)*(res+1)];
  
      uint16_t variance = 2000;
      int seed = 1337;
  
      data[0] = ((seed&gt;&gt;1)+(int)(rand()/(RAND_MAX*(seed+(seed&gt;&gt;1)))));
      data[res] = ((seed&gt;&gt;1)+(int)(rand()/(RAND_MAX*(seed+(seed&gt;&gt;1)))));
      data[res*res] = ((seed&gt;&gt;1)+(int)(rand()/(RAND_MAX*(seed+(seed&gt;&gt;1)))));
      data[res*(res+1)] = ((seed&gt;&gt;1)+(int)(rand()/(RAND_MAX*(seed+(seed&gt;&gt;1)))));
  
      int count = 0;
      for(int size=res;size&gt;=1;size=size&gt;&gt;1,variance=variance&gt;&gt;1)
      {
          count++;
          for(int x=size;x&lt;res;x+=size&lt;&lt;1) 
          {
              for(int y=size;y&lt;res;y+=size&lt;&lt;1) 
              {
                  data[x*res+y] = data[(x-size)*res+(y-size)] + data[(x-size)*res+(y+size)] + data[(x+size)*res+(y-size)] + data[(x+size)*res+(y+size)];
                  data[x*res+y] /= 4;
                  data[x*res+y] += (variance&gt;data[x*res+y])?(-(data[x*res+y]^2/variance)+(int)(rand()/(RAND_MAX*(data[x*res+y]^2/variance)))):(-variance+(int)(rand()/(RAND_MAX*variance*2)));
              }
          }
  
          for(int x=0;x&lt;res;x+=size)
          {
              for(int y=0;y&lt;res;y+=size)
              {
                  if(x!=res-1)
                  {
                      data[(x+(size&gt;&gt;1))*res+y] = data[x*res+y] + data[(x+size)*res+y] + ((y!=res-1)?data[(x+(size&gt;&gt;1))*res+(y+(size&gt;&gt;1))]:0) + ((y!=0)?data[(x+(size&gt;&gt;1))*res+(y-(size&gt;&gt;1))]:0);
                      data[(x+(size&gt;&gt;1))*res+y] /= (y!=res-1&amp;&amp;y!=0)?4:3;
                      data[(x+(size&gt;&gt;1))*res+y] += (variance&gt;data[(x+(size&gt;&gt;1))*res+y])?((-(data[(x+(size&gt;&gt;1))*res+y]^2/variance)+(int)(rand()/(RAND_MAX*(data[(x+(size&gt;&gt;1))*res+y]^2/variance))))):(-variance+(int)(rand()/(RAND_MAX*variance*2)));
                  }
                  if(y!=res-1)
                  {
                      data[x*res+(y+(size&gt;&gt;1))] = data[x*res+y] + data[x*res+(y+size)] + ((x!=res-1)?data[(x+(size&gt;&gt;1))*res+(y+(size&gt;&gt;1))]:0) + ((x!=0)?data[(x-(size&gt;&gt;1))*res+(y+(size&gt;&gt;1))]:0);
                      data[x*res+(y+(size&gt;&gt;1))] /= (x!=res-1&amp;&amp;x!=0)?4:3;
                      data[x*res+(y+(size&gt;&gt;1))] += (variance&gt;data[x*res+(y+(size&gt;&gt;1))])?((-(data[x*res+(y+(size&gt;&gt;1))]^2/variance)+(int)(rand()/(RAND_MAX*(data[x*res+(y+(size&gt;&gt;1))]^2/variance))))):(-variance+(int)(rand()/(RAND_MAX*variance*2)));
                  }
              }
          }
      }
  
      size_t Count = res*res;
      uint16_t* Block = data;
      char* Path = "export.raw";
  
      if(!Block) return false;
      FILE * filePointer = NULL;
      errno_t error = fopen_s(&amp;filePointer, Path, "wb");
      if(error) return false;
      fwrite(Block, sizeof(uint16_t), Count, filePointer);
      fclose(filePointer);
      return true;
  
      return 0;
  }
  </code></pre>