3

Given

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

And main.C being

#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 result in a compiler error? I thought C++ does not have VLAs?

Executing the program works just fine.

8
  • 6
    It's a gcc extension. You're right that it's not in the standard. Commented Sep 16, 2014 at 12:41
  • 3
    compile with --pedantic to ensure standard c++ Commented Sep 16, 2014 at 12:42
  • How can I compile against the c++ standard only? Is there some flag for gcc? (g++ is not available for me atm) Commented Sep 16, 2014 at 12:42
  • @BeyelerStudios one second faster than me, thank you ;) Commented Sep 16, 2014 at 12:43
  • If anybody knows how to make the title of the question more specific feel free to edit. Commented Sep 16, 2014 at 12:44

1 Answer 1

0

This is a GCC extension and doesn't have anything to do with your approach of compiling with gcc then manually linking the C++ standard library.

The --pedantic compilation flag will typically disable such extensions.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.