Array declaration

To add comments, please log in or register
DAHUMEO
133
DAHUMEO  
int array[OrdersTotal() ];
Why can't I declare like above ?
Simon Gniadkowski
17644
Simon Gniadkowski  
dahumeovn:
Why can't I declare like above ?

You cannot,  instead use ArrayResize()

 

int array[];

ArrayResize(array, OrdersTotal() );
GreenMoney
369
GreenMoney  
dahumeovn:
Why can't I declare like above ?

I believe an array's elements must be literally declared at compile time, rather than simply at runtime.  

The following generates a compile error...

int x = 1;
int array[x];

however, the following does not:

int x = 1;
int array[];
ArrayResize(array, x);

So, as RaptorUK suggested:

int array[];
ArrayResize(array, OrdersTotal());
To add comments, please log in or register