c++ - Why does this snippet produce no output -


i reading use python scientific computing, , decided test code myself. c++ code (with bit modification)

#include <cstdlib> #include <ctime> #include <iostream> #include <cstring>  int main() {     std::clock_t begin = std::clock();     double a1[500][500];     double a2[500][500];     double a3[500][500];     memset(a1, 0, 500*500*sizeof(double));     memset(a2, 0, 500*500*sizeof(double));     memset(a3, 0, 500*500*sizeof(double));     int i, j, k;     for(i = 0; < 500; i++) {         for(j = 0; j < 500; j++) {             for(k = 0; k < 500; k++) {                 a3[i][j] += a1[i][k] * a2[k][j];             }         }     }     std::clock_t end = std::clock();     std::cout << (double)(end - begin) / (double)clocks_per_sec<<std::endl;     return 0; } 

it simple code, weirdly no output @ generated. not 0, nothing. tried vc11 , mingw 4.7, both produce nothing. when for loop inside removed code produce output, 0.

and if debug in vs 2012, exception of "stack overflow" thrown, while no error happens if not in debug mode.

what reason weird behavior?


edit

so used new , time there normal output 0.83.

still, find curious stack overflow error not shown, program exits without giving output.

you ran in 2 things:

  1. compiler\environment paramater difference. default stack size (a1, a2 , a3 allocated in stack) varies between compilers, operating systems. in ones stack not enough fit variables stack overflow exception
  2. difference in optimization level (suvp got 0.83 seconds): code execution time different depending on optimization. compiler can notice loop nothing in particular , remove it. can go further , realize memset not useful , remove them too. if loop executed is, there 125 millions operation on double, take more mere 0.8 seconds.

the test in post linked flawed beginning...


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -