Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

> C supports variable-length stack-allocated arrays, while C++ doesn't. So > code like > > void f() { > int x; > scanf("%d", &x); // read from user > int numbers[x]; // dynamic > }

I just pasted this in a file (and added `#include <cstdio>`) and compiled with g++, and it gave no errors or warnings and produced a *.o file, so maybe it does work?



view as:

That's because gcc supports it as an extension to C++. It's not an official part of the language, and using it in C++ code is therefore not portable across compilers/platforms.

clang++ seems to work as well. I don't have a Windows machine handy to try MSVC, though

Legal | privacy