declare a table size with an external variable

 

Hi everyone,


my issue is well summarized in the title of the topic. I would like to be able to declare a table of variable size according the configuration before launching the EA.


Now I am using


#define WINDOW 20

...

int tab[WINDOW]


But I would like to be able to modify this size with an extern variable. Of course, if I try the following code it doesn't not compile because "window is not an integer variable" according the compiler...


extern int window;

...

int tab[window];


If someone can help, I would be very grateful.


Thanks a lot,


Altaïr

 
altair_606:

my issue is well summarized in the title of the topic. I would like to be able to declare a table of variable size according the configuration before launching the EA.

[...]

Sounds like the following should work - i.e. leave the size uninitialised, and then initialise it during init() using the ArrayResize() function.


extern int window;

int tab[];

...


int init()

{

...

ArrayResize(tab, window);

...

}

 
Thank you a lot. It seems to work.
Reason: