[sclug] g++ c++ question

Simon Heywood simon at triv.org.uk
Sat Oct 25 09:05:53 UTC 2003


On Thu, Sep 11, 2003 at 03:14:40PM +0100, Tim Sutton wrote:
> dataprocessor.cpp:780: error: ISO C++ forbids variable-size array ` 
> 
> The offending code snippet looks like this:
> 
>        int myArrayLengthInt = theClimateVector.size();
>        float myClimateArray[myArrayLengthInt];

I'm surprised that this compiled at all. You're generally not allowed to
create an array using a variable as the array size; one tends to use a
compile time constant for such things.

The C way to do it is with malloc() but in C++ you can do something like
this.

	float *myClimateArray = new float[theClimateVector.size()];

Then you can use things like "myClimateArray[0] = 2.71828f". Not
particularly unpleasant.

> 1) Did gcc / g++ 3.3 introduce some incompatiblility / stricter standards 
> checking that is affecting me?

Presumably.

S.



More information about the Sclug mailing list