0

I want to use a couple of interger and float arrays in C++ for a project but the code would compile and not run. When I inserted checkpoints in the code, I found out that issue is with the blocks of array declaration. Please is there anything wrong with my code.

int main(int argc, char *argv[]) {

    int row = 0, col = 0, num_rows = 512, num_cols = 512, quant;
    int x[num_rows][num_cols], quantIndices[num_rows][num_cols];
    float diffHat[num_rows][num_cols], xHat[num_rows][num_cols], xTilda[num_rows][num_cols], 
    diff[num_rows][num_cols];

    //some more codes

    for(row = 0; row < num_rows; ++row){
       for (col = 0; col < num_cols; ++col){ 
       //more codes that will involve all the arrays
       }

    }


return 0
}
Syn Joseph
  • 11
  • 2
  • Also note that VLA (variable length array) is not part of C++ standard! It is compiler extension, added so you could mix C++ with C. It doesn't work on MSVC since it supports old C standard which do not have VLA yet. – Marek R Sep 09 '21 at 15:18
  • ***Please is there anything wrong with my code*** Your arrays are too large for the stack. Typically a stack is between 1 and 8 MB total. On msvc its 1MB by default. – drescherjm Sep 09 '21 at 15:20

0 Answers0