C++ array size dependent on function parameter causes compile errors

后端 未结 7 1790
甜味超标
甜味超标 2020-12-03 14:10

I have a simple function in which an array is declared with size depending on the parameter which is int.

    void f(int n){
        char a[n];
    };

    i         


        
相关标签:
7条回答
  • 2020-12-03 14:55

    Your method of allocating from the stack is a g++ extension. To do the equivalent under MSVC, you need to use _alloca:

    char *a = (char *)_alloca(n);
    
    0 讨论(0)
提交回复
热议问题