Why can i declare an array with a predestined size on gcc but not on visual studio c++?

后端 未结 2 1277
谎友^
谎友^ 2021-01-24 09:40

i was wondering why i can do this code in linux but not on visual studio? (File -> main.c)

int size;
printf(\"Size:\");
scanf(\"%d\",&size);
int vec[size];
<         


        
2条回答
  •  抹茶落季
    2021-01-24 10:30

    Does it have anything to do with c89 or c99 standard?

    YES!
    MSVC doesn't support C99. Variable length arrays are C99 feature.

    GCC also allow VLA as an extension so, you can compile your code in C90 mode.

    6.19 Arrays of Variable Length

    Variable-length automatic arrays are allowed in ISO C99, and as an extension GCC accepts them in C90 mode and in C++.

提交回复
热议问题