Search code examples
c++cintelicc

the Intel C/C++ compilers throw error during array initialization


I have regular C++ code for an array initialization to a value that compiles fine with the latest gnu compiler on Cygwin:

int main(){
    x = 10;
    int my_array[x][x][x] = {0};
    double my_other_array[x][x][x][x] = {0.};
    return 0;
}

However, when I transfer it over to the cluster and do the intel compiler (with all the fancy stuff for the mic coprocessors), the code will not compile, and it fails with the following error:

error: variable "my_array" may not be initialized

The error message disappears when I put the actual integers in the array box, rather than the variable.

However, the housing function of my arrays (in the actual code, not my example) gets called with inputs which determine the sizes of the array...so, while the array size does not change during the execution, I can't just put numbers in the array boxes (er, brackets)--they need to be the variables.


How to I implement this functionality with the intel compilers?


Solution

  • The use of variable sized arrays is a compiler extension and is not a standard C++ language feature. (It is a standard feature of newer specifications of the C language.) This is not supported in the Intel compiler.

    To declare the variable sized arrays you'll need to use std::vector or something similar.