I have the following code:
... int n; cin >> n; int numbers[n]; ...
It compiled from NetBeans on a Mac using g ++ (I think), and it did not compile using VS2008 on Windows. Why is it so hard to make it work with every compiler? The size of the array is known before it is allocated.
EDIT: I know about std::vector . This was actually part of my homework, and I started working on a poppy, and then returned home and was surprised that it did not work on VS2008. Thanks for all the answers. But I still think it is logical that if the compiler can generate some code like alloc(123) , where the value 123 is hard-coded, why can't it generate something like alloc(n) , where you get n from the memory address that contains int n or something like that. It seems more logical to allow something like this by default.
c ++ compiler-construction arrays visual-studio-2008 g ++
gyozo kudor
source share