Why can I declare an array with a predefined size in gcc but not in visual studio C ++?

I was wondering why I can do this code on Linux, but not on visual studio? (File → main.c)

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

Does this have anything to do with the c89 or c99 standard? Reason: I tried changing the flags to gcc and still worked.

0
source share
2 answers

Variable Length Arrays (VLA) is an addition to the C99 standard and until recently Visual Studio did not support C99 and, as far as I know, does not support VLA. If you build this in gcc outside of C99 mode, say in mode c90and use the flag -pedantic, it will give a warning:

: ISO C90 'vec' [-Wvla]

gcc VLA C99 ++.

, C11 VLA , , C11 6.10.8.3 , :

_ _STDC_NO_VLA_ _ 1, , .

+5

- c89 c99?

!
MSVC C99. - C99.

GCC VLA , C90.

6.19

ISO C99, GCC C90 ++.

+1

Source: https://habr.com/ru/post/1548723/


All Articles