Why can I define this variable length array in C ++?

Considering

gcc -c main.C
gcc -lstdc++ -o main main.o

And main.C

#include <iostream>

int main() { 
    int somany; 
    std::cin >> somany; 
    double ex[somany]; 

    for(int i=0;i<somany;i++){ 
            ex[i]=0.03; 
            std::cout << ex[i]; 
    } 
}

Why does this not lead to a compiler error? I thought C ++ does not have a VLA?

Program execution is working fine.

+4
source share
1 answer

This is a GCC extension and has nothing to do with your approach to compiling with gcc, and then manually binds the C ++ standard library.

The compilation flag --pedanticusually disables such extensions.

0
source

All Articles