vc++ expects const for array size!

Hello,

I wrote a C++ program for some data analysis in my lab. Using gcc in Linux, the program compiles and runs perfectly.

However, I now need to compile it so that it works as a command-line program in a win32 environment. I find myself forced to use Microsoft's Visual C++ Express 2010 (vc++). Unfortunately when I try compiling my program with vc++ I get an error telling me that the compiler expects a constant expression for the array size. Here is the code snippet that has the problem:

1
2
numbins = 2 * T / width + 1 ;
double hist [ numbins ] [ 4 ] ;


Where T and width are of type double and numbins of type long (defined previously). I REALLY need this array to be defined in the way it is now, because T and width are inputs from the user, thus the user can choose the number of bins. gcc/g++ has no problems with this expression.

As a side note, my code is based on an older C code, in which the same two lines of code appear and it has worked fine for more than 2 years. However, I believe the author of this code used Dev-C++ or some other IDE based of gcc. Unfortunately these versions no longer work with Windows 7.

Is there anyway to bypass this problem?
I must use VC++ in windows because I will be using ROOT (CERN's data analysis C++ framework) and they recommend VC++ on windows...
There is.
type* naem = new type[dynamic_size];

http://cplusplus.com/doc/tutorial/dynamic/

-Albatross
Oh... of course!

Thanks!
FYI, that statement is illegal C++, the only reason it works in g++ is because they are too lazy to remove that feature (it is valid C99 code).
Topic archived. No new replies allowed.